Justice Binta Nyako of the high court in the capital, Abuja, on Thursday awarded damages to 16 women who were arrested for prostitution in 2017.
It is the first time a Nigerian court has ruled on the legality of sex work.
A lawyer representing the women, Babatunde Jacob, told the BBC that the court upheld that security agents violated the rights of his clients when they broke into their homes alleging that they were sex workers.
Legal experts believe the judgement is likely to have far-reaching implications for Africa’s most populous nation.
The arrest of sex workers by security agencies is a common occurrence.
In a crackdown in May this year, more than 60 women were arrested in Abuja for prostitution.
Many of the women claimed they were harassed, extorted, and publicly shamed.
-BBC