Denmark's Supreme Court ordered the release of an ex-military intelligence chief held in custody for leaking information.