A federal court in Barcelona in the northeast of the country suspended a prison term of 15 months handed down in January to Muhammad Kamal Mustafa, 44, imam of the southern town of Fuengirola since 1992.
In Spain a sentence of less than two years is automatically a suspended sentence. But on 25 November another Barcelona judge ordered that the imam be sent to jail as it was considered he presented a danger to society.
In this latest decision the court agreed with Mustafa's lawyer that keeping the imam in prison would not help his reintegration into society.
However, it ruled that he should attend classes on the rights accorded to women by the Spanish constitution and on the Universal Declaration of Human Rights.
In his book, called "Women in Islam", which was published in 1997 in Spanish, Mustapha had given practical advice about inflicting physical punishment on women designed to be "a simple symbolic suffering which should not be excessive".
However judicial sources told AFP they were surprised by the original decision to put the imam behind bars, a ruling they described as without precedent.
They said the imam "represented a much greater social danger inside a jail."