The railway always has the right of way. In Costa Rica it is no exception.
What we see in the photo is the lack of responsibility of the municipality issuing building permits on a lot that fronts on a rail right of way and a bunch of other people who never imagined that one day there would actually be rail line built.
This is the result of the expansion of the Heredia commuter train from Heredia centre to Alajuela, affecting many properties. The same occurs in Belen.