Tens of thousands of passengers who were prosecuted and fined for fare evasion are set to be refunded after a judge ruled that their convictions were void.