Silver traditionally represented wealth, and that association extended to sweets to convey ‘meant for the wealthy’ (same as with silver crockery v/s bronze or copper ones). Silver was also considered an aphrodisiac. All Indian food additives, whose presence cannot be explained in terms of cuisine logic, made an appearance due to one of these 2 reasons. The other plausible reason could be that the foil reduces moisture evaporation, and hence it would prevent the sweets from drying out.
It’s not just India and it’s not just silver.
The use of gold and silver foils or leaf has a history that goes back hundreds of years in S. Asia, the Middle East, and Europe. The purpose is luxury. By having the foil on foods, the person offering the food is showing both a) he can afford to have you eat precious metals at his expense, and b) you’re a worthy-enough guest for him to do so.
With extremely rare exceptions, there’s no health issue at stake in eating gold or silver in these amounts.
It is used in Indian medicines and even vessels/cutleries are made of silver for the same reason. Since it is expensive, the way it is presented/designed on the sweets is a combination of creativity and advertisement to lure the ones who can afford to buy them.