Such legal opinions are not legally binding but are often followed by the court.
"Even if this is not the final decision on the matter, this is good news as the advocate general's opinion argues that the European Parliament is competent to defend Mr. Junqueras' immunity," said Ska Keller, the president of the Greens/EFA group in EU Parliament, with which Junqueras is allied.
"We hope that this important decision will now be confirmed by the (court)," Keller said. "We have always defended the right of our colleague to take up his seat."
Junqueras, who has been detained in Spain since November 2017, was elected as a member of the European Parliament in May. But Spain's Supreme Court refused to allow him out of jail to take the oath that Spanish law requires, and his seat was declared vacant.
Junqueras, who has since been convicted and given a 13-year sentence for sedition and misuse of public funds, brought the loss of his rights as a European lawmaker to the Supreme Court, which referred it to the European court.
Szpunar said that unless a European lawmaker's immunity has been waived by the European Parliament, Spanish authorities are "required to refrain from any measure which might obstruct the necessary steps" of the member to take up his role.
Alongside Junqueras, two other Catalan leaders — former regional leader Carles Puigdemont and Toni Comin — have been barred from taking their seats at the European Parliament because they have not taken the oath. Both currently live in exile in Belgium and are fighting extradition to Spain.
Puigdemont welcomed Szpunar's opinion, saying on Twitter that it "demonstrated another injustice" against Junqueras.
It remains unclear what it might mean for Junqueras should the court back Szpunar's opinion. Leading Spanish daily El Pais said Puigdemont and Comin would likely use it to try to take their seats and get immunity.
Insisting on the "constitutional importance of the case," Szpunar said European lawmakers' status should be overseen only by EU law, "failing which the Parliament's independence and the autonomy of the EU's legal order overall would be called into question."
Szpunar said that taking the Spanish oath was not a necessary step in the process of Junqueras' election to the Parliament, and that he should therefore benefit from immunity.
Noting that the Parliament did not have the opportunity to discuss Junqueras' immunity, he recommended that the Court declares that it falls to the EU Parliament to decide "whether it is appropriate to waive or defend the immunity of one of its members."
Ciaran Giles in Madrid contributed to this report.