The game tries to build the track that way, that your trains can move as fast as they can.
If you’re alrdy rich, this is a pretty good way to improve your routes or build new routes very fast and easy.
If you want your tracks to follow the terrain, build in short pieces.
Also make sure, the inclination indicator (the Thing with the ground symbol and arrow above it next to the tick) has a grey background. If it has a blue background and the up and down arrow, then manual inclination control is turned on and it doesn’t build like above said, then it goes straight down or straight up.