Somnath was one stop in a pattern of campaigning that had been running for a quarter of a century by 1026, and it makes more sense inside that pattern than outside it.
The pattern
Mahmud of Ghazni raided into the plains of northern India repeatedly from about the year 1000 onward. The expeditions were seasonal, they were aimed at movable wealth, and they were not attempts at settlement. Ghaznavid rule was consolidated in Khurasan and around Ghazna, not in Gujarat. The Punjab was the exception, and it was annexed rather than raided.
Why a temple
Great temples in this period were also treasuries. They held endowments in gold and silver, they received the gifts of merchants and of kings, and a coastal site like Somnath sat beside one of the busiest trading harbours on the Arabian Sea. A raider looking for portable wealth in western India would arrive at Somnath by arithmetic and not only by iconoclasm.
What the wealth was for
Ghazna was an expensive court fighting expensive wars on its Central Asian frontier, and Indian plunder financed a Persianate capital far to the north-west. The reputation of the idol-breaker that the court poets built for Mahmud was itself a political asset in his dealings with the caliphate at Baghdad.
None of this makes the raid smaller. It places it. An act of war and of profit, told afterwards as an act of faith by people who gained from the telling.