Try this, by train:
1.- Take a day train from Rome to Milan
2.- Take the overnight Tren Hotel from Milan to Barcelona.
3.- From Barcelona to Madrid you can take a day train
For Barcelona-Madrid schedules:
RENFE For Milan to Barcelona:
Elipsos Is not the pass you are refering to EURORAIL PASS?
It's for bordering countries, but not in the sense you mean: you can't "jump" from a country to another country which does not share border, but you can do "consecutive" countries. Your trip would be correct: Italy-border-France-border-Spain