I'll try to give a quick insight. I'm on a mobile, please excuse any typos.
Spanish and Portuguese "homeland" are not necessarily close: Portuguese language started taking form in Galiza and Castilian language took form around the city of Toledo. Very different places geographically. Also, we even have between them other Romance dialects, such as Asturian and Leonese.
You need to take into consideration as well that the Spanish-Portuguese borders are roughly the same for more than 500 years. Spain and Portugal are the oldest nation-states in the world and the creation of a national language is a substantial part of the process of creating a nation.
Despite all that, the written standard of both languages share a high degree of multual intelligibility (as a Portuguese-speaker I can understand 80-85% of written Spanish). Oral comprehension, on the other hand, involves far more variants which may vary from a dialectal or even personal basis.
I'm a linguist, so this is not a historical answer, sorry.
While they are certainly close enough to influence each other, it isn't unusual to have very different languages in close proximity, an indeed there are two other native Romance languages, as well as Basque on the Iberian Peninsula. This is low compared to other parts of the world. Nigeria is about twice as large but has 521 languages.
Again, this is abstract, and I'd love for someone to give a specific account of the interchange between Portuguese and the other Iberian languages, but I can tell you that sounding different is a sociological thing as well. Sociolinguistics tells us that people will emphasize regional pronunciation differences if they feel positively about their local culture. You've probably experienced this no matter where you live. So that could mean they may sound so different because they are close together, but also wish to remain culturally distinct.
From an english speaker point of view both languages could seem quite different, but the truth is they have many things in common. Spanish and Portuguese people can understand each other quite well, the same way they both have a conversation with an Italian and understand about 75%, because the 3 languages have a common base. This is not true, for example, with French, although a latin origin language too, but certainly quite different from the other three south european languages.
'Spanish' does not exist, rather you would need to speak of Castillian here. Castillian became the dominant language in Spain, especially after the Reconquista in the 15th century.
In the Iberian Peninsula, many more languages were spoken back in the 15th century than nowadays. And each language developed in own special way, as is the case with any language. There are no fixed rules here.
Likewise, we could ask why Castillian and Catalan sound so different, or we could ask why Galician and Catalan are so different.
A very good book about the history of the Castillian language, is 'The Story of Spanish', written by the very talented Canadian couple, Barlow and Nadeau.