Gurkhas who fought alongside UK troops have won the right to settle in Britain after a "victory for common sense".