In most cases, babies wear eyeglasses because they suffered from some vision problems. Lazy eyes are considered the most common vision problem for them. So, they wear eyeglasses to correct their vision or practice their lazy eye. Besides, some baby born with poor vision because of myopia (maybe). Although it is rare, it is happy. So, hey need eyeglasses to see better. Of course, there are some babies wear plano eyeglasses for fun.
Many babies wear glasses to correct their vision problems. My nephew has vision problems since he was born. So he needs to wear prescription glasses and do eye exercise every day. His parents bought a machine for him to do this eye exercise but finally it turns out that it hasn't improved his eyesight. Now he also needs to wear glasses every day.
Only some of them would wear glasses just for a cool look. In fact, babies have a 65% chance to get myopia throuht genetic inheritance if there parents get severe myopia. So they wear eyeglasses just to correct their vision problems.