Ugandan opposition leader Kizza Besigye has been released on bail , after a judge ruled his detention by the military was illegal .