You only can ride them after you beat the Elite Four if you get passes to board them.
After beating the Elite Four, find Prof Elm, and he will give you the SS ticket.
You can get the train pass in Saffron City from a girl nick-named "Copycat". If you talk to her, she will tell you that she lost her favorite doll. Fly to Vermillion City. There is a man next to a Clefairy doll. If you speak with him, he will give it to you. Go back to Saffron City and talk to Copycat to give her back her doll. In return, she will give you the Magnet Train Pass, allowing you to ride the trian.