Also, a good railway increases profits elsewhere, in addition to fares, as people can cheaply and relatively comfortable travel across the country.
Correct, but Iryo is a private company, although the railway in Spain is publicly maintained i guess by Renfe. So i believe Iryo should make money, specially (as mentioned in another comment below) it's part of Trenitalia. But i'm definitely not an economist.
The public railway infrastructure is maintained by Adif [1], which is owned by the Spanish state.