I was just thinking about this that as all probes have solar panels attached to them so why do they have to shut down at the last stage, So I googled and found that dust sticks to panels because of which they cannot function properly.
But suppose I put glass/any material covering around solar panels, Is this a more power-consuming task to clear the glass again so that again sunlight will pass inside panels? I know it kind of sounds stupid but I am not able to swallow that solar panels cannot function eternally for probes?
According to me at least they should function for 100 years :P
A glass cover isn't enough. The damage is caused by micrometeorite impacts. These are tiny particles that hit at high speeds (more than 1 km/s). You can't build solar panels to withstand that much energy.
Also, it's rare for a mission to end because the solar panels no longer provide enough power. Other factors end the mission long before the solar panels degrade that much:
component failure (especially mechanical components like reaction wheels)
end of mission funding: science missions are usually designed to last a predefined period. Some missions are extended, on others the plug is pulled when the original mission ends. Commercial satellites are replaced on a schedule.
Not all spacecraft have solar cell arrays. Many sent to Jupiter and beyond use generators powered by radioactive decay because sunlight is very weak beyond
Mars's orbit. Some spacecraft use full-blown nuclear reactors - such as various old Soviet spy satellites.
Your reference to "dust" makes me think you actually mean Mars rovers, because Mars (unlike space) is a very dusty environment. The Curiosity Mars rover is powered by radioactive decay and has no solar cells. The Opportunity and Spirit Mars rovers operated for years despite having no means of cleaning the dust off their solar cells. It turns out that Mars winds did a good job of keeping their cells reasonably clean (at least in the locations those rovers were deployed in). Contact was only lost with Opportunity after 14 years of operation in 2018 as sunlight was blocked by a Mars-wide dust storm. As the storm's dust was in the air, and not on the solar panels, cleaning apparatus would not have helped. In addition, Opportunity died because it could not keep its batteries and other systems warm during the storm - post-storm its solar cells may well have been working OK.