The short answer is spring and autumn. From March to May and from September to early November, the cities are warm enough for long days outdoors without the punishing heat of high summer, the queues at the big sights are shorter, and hotel prices sit between the summer peak and the winter low.
The longer answer depends on where you are going. Spain's climate changes a lot from region to region: the interior plateau around Madrid has hot summers and cold winters; Andalusia in the south is the hottest part of Europe in July and August; the Mediterranean coast is mild most of the year; and the Atlantic north around San Sebastián is green because it rains in every season.
For travellers from India, the main holiday windows each have a sensible Spain plan. Summer school holidays suit the coast and the islands, with the cities seen early and late in the day. Diwali in October or November is close to ideal everywhere. The Christmas and New Year week brings festive lights, cool sunny days in the south and the cheapest months that follow.