Why did my train choose the blocked path at the junction?

I am new to train signals. Here's a situation I don't understand:

OpenTTD train signals

There are three signals. The signal at the entry of the Y-junction (on the bottom right) is an "entry signal". The other two signals are "exit signals". There are two possible paths for the train. One path is blocked by a crashed train. The path other is free (as evidenced by the green light). Yet, the train decides to take the blocked path! Why?


Pathfinding

Signals do not affect the path a train takes directly: A signal can only force a train to stop and start, but cannot dictate its direction. While this is true, trains do take signals into account when choosing a path: red signals confer a pathfinding penalty.

OpenTTD has a complex pathfinder in it. The train chose to go left because the pathfinding penalty for the route on the left was smaller than that for the route to the right. I cannot see what's behind both choices so I cannot say for sure what's causing this to be the case.

If the train cannot get to its current destination via the right path, it will always choose the left path: the penalty is infinite.

If it can, but you built a massive rail maze behind that signal on the right, it will still choose to go left.

If it can, but there are a lot of trains and red signals behind that signal on the right, it will also choose to go left.

Fixing your situation

I would recommend using CTRL-click on that signal,with the signal build button pressed, to turn it into a one-way signal in the wrong direction. This makes it impassible without costing you any money. When the crashed trains clear up (in about 3 months from now) change the signal back to its normal state.