Freemasons were not behind the expulsion of the Jesuits from Spain. King Charles the III had a decades long dispute with Rome by the time the Jesuits were expelled from Spain which predated him becoming King; and this wasn't the first time Charles III focused reprisals against Priests in lands he ruled. The expulsion of the Jesuits was done in service of secular nationalism by the King to exhort his control, and dominance over the Church; which had set itself up as his rival/enemy (after he conquered a Papal Fiefdom). The Freemasons were ancillary beneficiaries of this Royal act, not instigators.
Catholics were forbidden from becoming Freemasons since the Papal Bull of 1738. It is not a coincidence that the "first" Freemasons lodge in Spain corresponds with the expulsion of the Jesuits 1767. Prior to that the Inquisition rooted out and shutdown Freemason lodges as they formed. The church's problem with the Freemasons was that they were a religiously agnostic organization. Freemasons took a pledge of religious equality among members which superseded all other commitments. This put them on the opposite theological teaching to midivil Rome who's doctrine said Rome was the only path to salvation and every non Catholic should be converted even upon pain of death.
Important Dates for this Answer:
1478...........Spanish Inquisition begins
1517...........The Protestant Reformation begins
1540...........The Order of the Jesuits is formed
1648...........The Protestant Reformation ends
1717...........Grand Lodge of London and Westminster (later, of England) formed
1731...........Charles III becomes Duke of Parma and Piacenza
1734...........Charles III conquers Naples and Sicily appointing himself king of both
1738........... Pope Clement XII issues Papal Bull forbidding Catholics from becoming Freemasons. (In eminenti apostolatus specula)
1756...........The Seven Years war Begins
1759...........Charles III becomes King of Spain
1763...........The Seven Years war ends with France and Spain losing.
1767...........Charles III of Spain expels Jesuits from Spain
1773...........Pope Clement XIV dissolves the Jesuits
1788...........Charles III dies
1814...........Pope Pius VII reestablished the Jesuits as an order
1834...........Spanish Inquisition ends
More Detailed answer
Charles the III of spain was a generational strong leader who had a history of standing up to Rome.
Charles III: Relations with the Holy See
Historian Stanley Payne wrote that Charles III "was probably the most successful European ruler of his generation. He had provided firm, consistent, intelligent leadership. He had chosen capable ministers....[his] personal life had won the respect of the people."
Charles III was in contention with Rome for a long time before he became King of Spain. Where the Protestant Reformation had checked Papal power in much of Europe, Naples, Sicily and Spain (Charles domain) were not part of that Reformation. Where Charles III reigned monarchs were still struggling with Papal authority rivaling their own.
The Pope (Clement XIV) and Charles III struggled first over The Kingdom of Naples. Naples had been conquered by Charles III in 1734, but was a traditional fiefdom of the Vatican.
Charles III: Relations with the Holy See.
The Kingdom of Naples was an ancient fief of the Papal States. For this reason, Pope Clement XII considered himself the only one entitled to invest the king of Naples. He did not recognise Charles of Bourbon as a legitimate sovereign.
The Vatican did not recognize Charles III claim by conquest of Naples and denied Charles investiture.
Papal Investiture was a long standing dispute between European Monarchs and the Holy See. It was a central disagreement inspiring Royals in Protestant Europe (Germany, Switzerland) to support the Protestant Reformation and ultimately a great schism with Rome. At it's basis it was about who could appoint Bishops, clergy, and important church offices within a Kingdom, the Pope or Monarchs. Popes long had this right and Monarchs long fought for this power as a check on Papal influence, power inside their kingdoms. The Pope who didn't recognize Charles III conquest, refused this right for Charles in a time when other rulers had been granted it.
Charles responded with a legal argument claiming Papal investiture was not a sacrament of the Church thus the Pope had no right to deny it to the monarch. Charles III backed up by his father the King of Spain ultimately won the confrontation. Charles then elevated the confrontation by curtailing the privileges of the clergy in Naples. This was done as a punitive measure and also as a practical matter. The clergy was a wealthy class who's holdings were not taxable prior to that point. Taxing and confiscating their wealth was lucrative source of revenue for Charles who had conquest and governance to pay for. Repealing the privileges of the clergy was also a way of showing his independence even dominance over the church. The conflict with Rome was public and the Catholic people who had Long been citizens of Rome(fiefdom) reacted to Charles III's new rule with riots and even attacked the Spanish Embassy. Charles further blamed Rome.
This confrontation would fester with the Pope who would seize opportunities to snub Charles, and Charles getting more punitive with the Church and it's functionaries.
When Charles III became King of Spain in 1759 he would bring his conflict with the Vatican with him. Spain was in the middle of the 7 years war with England, a war they would ultimately lose. Spain required funds. Again Charles moved to tax church property which was vast. Spain had endured nearly 200 years of inquisition, which had both swelled church officials in Spain and the purses of this officials. Among the wealthiest, best educated, and most fanatical order of Catholic Priests were the Jesuits.
The Jesuits were founded by Saint Ignatius de Loyola. A former Soldier crippled in the Battle of Pamplona in 1521. The Jesuits were a (-*-)fanatical Catholic order, who brought a military discipline to the faith. They were dedicated to education and learning, and this meant they were consistently among the smartest, best educated, and most influencial clergy. They became very involved in both the Papal and Spanish Inquisitions and counter Reformation in general. They are credited with returning many protestants to the faith during the Counter-Reformation in which torture, confiscation of wealth, and imprisonment were means of coercion. They were an obvious target for King Charles III, because they were wealthy, highly educated, highly influential, and fanatical about Catholicism. Any secular leader trying to assert power over Rome would find the Jesuits a formidable advisory, which lead to their deportation and ultimate disbanding for a few decades.
As for the Free Masons.
From Catholic Harold: The real reason Catholics can’t be Freemasons
the Church became the greatest foe of the Masonic lodges. Between Clement XII in 1738 and the promulgation of the first Code of Canon Law in 1917, a total of eight popes wrote explicit condemnations of Freemasonry. All provided the strictest penalty for membership: automatic excommunication reserved to the Holy See.
What Clement XII described in his original denunciation was not a revolutionary republican society but a group spreading and enforcing religious indifferentism: the belief that all religions (and none) are of equal worth, and that in Masonry all are united in service to a higher, unifying understanding of virtue. Catholics, as members, would be asked to put their membership of the lodge above their membership of the Church. The strict prohibition, in other words, was not for political purposes but for the care of souls.
They were a organization, which was in direct contention with the Inquisition and the Jesuits. Catholics had been forbidden to join the organization by Papal bull in 1738, and given Spain 200 years into the Inquisition was almost completely Catholic that mean the Jesuits were free to "inquire", "inquisite" Freemasonry.
Initially, the membership of Masonic Lodges in Spain consisted of expatriates from Britain and France, but it was not long before Spaniards began to join. In spite of this, for most of the eighteenth century no organized and stable masonry arose in Spain. The few lodges that were founded had a brief and precarious life because the Spanish Inquisition were quick to prosecute, enforcing the papal bulls and the decree of Fernando VI on 2 July 1751 banning Freemasonry. For example, the military lodge founded in Barcelona in 1748 that had begun in Nice was denounced to the Inquisition just two years later and closed down. It was reorganized in 1776, but again the Inquisition stamped it out and arrested all its leaders.
Jesuits as fanatics...
Fanatic is defined as a person filled with excessive and single-minded zeal, especially for an extreme religious or political cause. The Jesuits were founded by a crippled soldier, who prescribed bringing military discipline to the faith. They represented themselves as God's Soldiers. In their war they were willing to torture and kill, and they were willing to endure torture and death.
Jesuit Order Established
The life of a Jesuit was one of immense risk, and thousands of priests were persecuted or killed by foreign authorities hostile to their mission of conversion.