Pope Leo has addressed Spain's parliament, urging politicians to work to end wars and help migrants at a time of "violence, polarisation, and mutual distrust".