Gurkhas have lost a bid to overturn a ruling that stopped them automatically settling in the UK after Army service.