smps block diagram and working for isolated topology
You got part of the answer in the comments: because mains frequency is lower than the operating frequency of the power supply.  Up to a point, the higher the frequency, the smaller the magnetics can be.  Typical mains frequencies are well below that point.

The other part of the answer is that the square pulse that is generated has a controlled duty cycle, so that the output voltage of the supply can be regulated.

It is possible to use a transformer at the mains frequency and rectify the output -- this is how the job was done just about everywhere until the 1970's, still in a lot of places until the end of the 20th century, and is still found in a few places now (ca 2019).