Leo’s Encyclical, In Eminenti, was particularly aimed at outlawing membership in Masonic organizations for Catholics. This is reflected explicitly in the 1917 Code of Canon Law, and then it is argued the ban is upheld implicitly in the 1983 revision of the Code of Canon Law, as per then Cardinal Ratzinger’s clarification. However, encyclicals, in general, are not infallible declarations, although they can contain infallible magisterial teaching (
forums.catholic-questions.org/showthread.php?t=109552).
A number of factors influenced Leo’s declaration. One such factor was the Taxil Hoax. This was an elaborate hoax whereby Taxil claimed that he knew various Masonic lodges in Paris that were working to subvert the Church, which he published in a play, claiming it as a representation of the truth. Supported by the local bishops, it was a highly embarrassing moment when Taxil came out at the end of the play, in which the bishops where in attendance, and laughed at everyone there, saying it was all a hoax and was designed to parody the Church, because he had a bone to pick with the Church.
Another aspect was the political nature of Italian lodges. Freemasonry came out in the open in 1717, when four lodges in London formed the Grand Lodge of England, now known as the United Grand Lodge of England, a history which would be too periphery for this conversation. Italian lodges, at the time of Leo, were largely irregular, or in other words, not recognized as authentic according to the terms of regularity for Masonic lodges. A quick flash forward, many Catholics are quick to ‘prove’ that masonry is ‘bad’ due to a scandal in the 80’s involving a lodge in Italy known as the P2 lodge. However, again, this lodge was not associated with regular freemasonry, and the regular lodges of Masons were not associated with the P2 rogue lodge.
Freemasonry, as a side note, is not a religion, nor a substitute for one.