Learning to fly is not cheap, and you are likely (depending where you are studying of course) in a minority, if you are there as a hobbyist, because I would expect that most of the other students have a professional future as a pilot in their minds. For them, it is a serious business in all respects.
Professional pilots, in civil aviation or the military, will generally wear a uniform. The uniform, like much of the profession, is derived from naval traditions, where rigour and discipline are valued in appearance as much as in conduct and exercise of duties.
Dressing smartly doesn't mean someone is a better pilot, and dressing casually doesn't mean the opposite. However, attention to dress indicates attention to detail.
In aviation, precision and formality in thought, actions, speech and behaviour are key to safety and correct operation (we wouldn't be too happy to hear an airline pilot announce "Uh, yeah, we'll be, you know, heading in like an easterly direction an' that.")
If crisp formality is key to good piloting (and I think it is) then it seems reasonable to expect to hear it, feel it and see it all around you in flight school - including in the way fellow students dress.
Then there are more practical considerations. If everyone is dressed similarly, in something approaching a uniform or at least a standard, then it becomes easier to see when something is wrong or out of place (for example, if someone is unwell).
When actually flying or working around machinery, some attire is certainly suitable or unsuitable. Flappy garments that obscure instruments or catch controls or switches as you move are obviously dangerous. Shoes need to be appropriate for the job, and so on.
Depending on the kind of plane, the cockpit can also be a potentially hazardous environment, in which smoke, fumes, fire, fluid leaks and so on can occur.
A shirt and tie don't offer you better protection than a tracksuit from those (unless you like to wear, say, a nylon tracksuit), but wearing otherwise appropriate attire is a signal that you are generally aware of the environment and its demands and expectations.
It could also be that your flying school formally sets out an expection or a requirement ("For classroom-based instruction, we expect [or even, require] male students to wear shirt and tie, etc etc.") and that somehow you have missed it - in which case perhaps your fellow students are aghast at your daring flouting of the rules.
It never hurts to ask: is there a dress code?