Hey, if Castile weren't in a personal union with Aragon would a Castilian-Portuguese union have worked, with Aragon independent?
No. But since you're asking, I'm posting a lengthier answer.
It was tried several times, and always found very strong opposition from the nobility of the other kingdom, and even from the people (at least the townsfolk).
Ferdinand I of Portugal tried it in 1369, and was eventually defeated by Henry II of Castile, a bastard of the castilan royal line.
John I of Castile tried it in 1383, met strong resistante in Portugal, was defeated after several years and the portuguese crown passed to a bastard of the portuguese royal line.
Next it was Afonso V of Portugal who tried a union, in 1474: married to the legitimate (if disputed) heiress to the castilan crown, we was defeated by an alliance of castilan nobles who backed Isabella - that one broke the trend, she wasn't a bastard.

A few years later John II of Portugal had his son wed to the eldest daughter, and likely heir, of Isabella and Ferdinand. But he died in 1491, apparently in a riding accident. Isabella was suspected of having had a hand at arranging his death (after the marriage she had not produced any reliable male heir, but hated John I and his son), but nothing was ever proven. John II died shortly after, in 1495, possibly poisoned with arsenic. He certainly had a large number of enemies, including most of the high nobility in Portugal, the catholic kings, and his own wife after their son died and he started favouring a bastard as heir.
Just a few years later another attempt: John I's successor, Manuel I, negotiated in 1496 a marriage with the heiress of the catholic kings. But she died giving birth, and the son they had died two years later. The price of the marriage, set by Isabella and Ferdinand, was the expulsion of the jews and muslims from Portugal. With hindsight, a very bad deal for Manuel and for Portugal. This attempt might actually have worked, as it was backed by the catholic kings who seemed to have quite a lot of influence over Manuel. But my guess is that the castilan nobility would again rebel - they feared any king who might have an independent power base, and it showed when they expelled Ferdinand II after Isabella's death. Even Charles V was resisted, though they never dared open rebellion.
Finally, in 1578, Sebastião of Portugal died without issue. His father had died before his birth, in 1554, and he had inherited the crown directly from his grandfather, John III, in 1557. The young child was abandoned in the portuguese court by his mother and left only with the weak protection of the widow queen, his aunt, who felt a need to guard him closely in the court (he slept in her rooms). That ended when he was twelve and his aunt was removed from the regency. He fell, for the rest of his life, under the control of a jesuit friar, his confessor, who had shown himself rather "fond" of the child. The king never married, would apparently even avoid women, but was plagued for almost all his life (since
before he ascended to the throne) by a disease of which the described symptoms exactly match those of gonorrhea.
All the other descendants of John III were dead by then, but one of his daughters had been married to Philip II of Spain, who through that could claim to be the heir to the portuguese crown. Again there was a rebellion against the prospect of a union, backing instead one of Manuel I's grandsons, António. Again a bastard, but this time the castilan monarch managed to buy important support in Portugal, and had a better army and navy. Antonio proved no match to the Duke of Alba and finally an Iberian Union was started under Philip II of Spain/I of Portugal, which lasted until 1640. When the trouble caused by the spanish kings became too great (high taxes due to the constant wars, the loss of markets in Flanders and Northern Europe, and the loss of colonies and trading posts), the spanish kings were kicked out.