Spain and France seemed to have a good relationship. Why compromise that?
It is difficult for one to characterize the relationship between Bourbon Spain and Napoleon as "good" as it was often quite the opposite. Both the Third Treaty of San Ildefonso in 1800 and the Treaty of Aranjuez of 1801 reorganized the Franco-Spanish alliance on terms highly favorable to France. This created a degree of resentment within the Spanish government and contributed to a generalized dissatisfaction with the direction Spain was heading. Manuel Godoy, Spain's Prime Minister and an arch-intriguer, had sent out feelers to Russia and Britain that should Prussia defeat Napoleon in 1807, Spain would abandon the French alliance and invade France. Evidence of Godoy's machinations came to Napoleon's attention which underscored to the Emperor that Spain was not a constant ally. Spain's military had contributed little to French goals in Portugal and its navy had not been successful against the British. Spanish domestic factionalism between the ruling king and his son also created a headache for Napoleon as each side expected him to act as an arbiter. These squabbles also built an impression in Napoleon's mind that Spain's inability to either reform or act as a proper ally stemmed from deep-rooted corruption inside the Spanish central government.
To put it succinctly, Spain presented Napoleon with a complex set of problems for French policy. The existing state of the alliance was producing less dividends for France and the complications of Spanish politics drew Napoleon deeper into Spain than he desired. So from Napoleon's perspective, the French invasion and putting his brother Joseph on the throne was cutting the Gordian knot of his Spanish problem. Napoleon expected that a rationally organized Spanish kingdom and empire would be effective in counteracting British power. A Spanish Bonaparte dynasty would ensure that Madrid could never intrigue against Napoleon. Subsequent events in Spain did not follow Napoleon's expectations. By forcing the Bourbons into exile, Napoleon made them a symbol around which the various Spanish political factions could rally. The compromised nature of Spanish sovereignty ensured that Joseph had difficulty winning hearts and minds and thus minimized the effects of French-inspired enlightened reforms. This made French rule over Spain dependent upon French arms, which in turn further alienated the Spanish populace from the new regime as these French troops needed Spanish supplies to operate and often took them by force. Thus Joseph became increasingly hostage to French military fortunes, which in turn made his rule ever more precarious. Far from resolving the Spanish issue, Napoleon's turning on his Bourbon ally made Spain an intractable problem for French policy.
Sources
Connelly, Owen. Napoleon's Satellite Kingdoms. New York: Free Press, 1966.
Dwyer, Philip. Citizen Emperor Napoleon in Power. New Haven, CT: Yale University Press, 2013.
Esdaile, Charles. The Peninsula War: A New History. London: Lane, 2002.