Pre-Civil War: Rooted in Animosity
Even before the tournament to crown Alfonso XII, Madrid and Barcelona were at odds. The governments historic centralism policies have always left many out of the conversation when it comes to politics. The inability to separate themselves from the influence of the government. At one point, the Catalans as a whole wanted to annex in to their own country. Nothing says animosity like that; it's American Civil War-esque..
When Francisco Franco Rose to power in the Spanish Civil War, he played on these preexisting rivalries to further centralize Madrid and attempt to alienate and even eliminate the Catalan Way of life. He at one point instituted legislation prohibiting the Catalans from using their language outside the home. It was not even allowed to be used in public documents like items pertaining their team FC Barcelona. They actually had to change the original name to it's Spanish equivalent which is FC Barcelona. Franco would do everything he could to retain power and discredit those whom he thought would try to remove him.
Goig, R.L. (2001). Identity, nation state and football in Spain. Soccer of Society, 9(1), pp.56-63. doi:10.1080/14660970701616738
Vacizi, M. (2015). The spanish fury: a political geography of soccer in Spain. International Review for the Sociology of Sport, 50(2). doi: 10.1177/101269071347894D