Flight Lieutenant Dr Malcolm Kendall-Smith, 37, who is based at RAF Kinloss in Moray, faces five charges of failing to comply with a lawful order after he refused to take part in training and deployment to Basra.
He had already served two tours of duty in Iraq, but refused to return there last June.
At a pre-trial hearing last week, Flt Lt Kendall-Smith's defence counsel, Philip Sapsford, QC, said the officer believed that because Iraq had not attacked the UK or one of its allies, there was no lawful reason to enter Iraq. On that basis, he argued that Flt Lt Kendall-Smith, who has dual citizenship of Britain and New Zealand, was entitled to disobey the "unlawful" orders.
"The flight lieutenant's case is that Iraq was and remains under occupation," Mr Sapsford said.
"He is entitled to say to this tribunal, 'I hold that belief honestly and, in these circumstances, it's my duty to disobey these orders'."
But the judge advocate, Jack Bayliss, ruled yesterday at Aldershot that Flt Lt Kendall-Smith should face trial.
He said the orders given to Flt Lt Kendall-Smith were lawful, adding: "None of the orders given to the defendant in this case was an order to do something which was unlawful.
"I also conclude that it is no defence to a charge of wilfully disobeying a lawful order that the defendant believed that the order was not lawful.
"That might be a point in mitigation, but it cannot provide a defence in law since the mens rea [legal basis] of the offence is a deliberate disobedience of an order which the defendant received and understood."
The judge advocate ruled that four of the five charges related to training prior to deployment, and therefore referred to legal orders given to Flt Lt Kendall-Smith. He said: "There can have been no possible illegality in complying with the orders to attend for pistol and rifle training, to attend for a helmet fitting and sizing, or to attend an initial response training course. Those are all activities ancillary to any deployment to an operational theatre."
He added that UK armed forces had full justification under United Nations resolutions to be in Iraq at the time of the charges, which date to June and July last year.
He said: "There is no ambiguity in the wording of either Resolution 1511 or Resolution 1546. It follows that I regard those resolutions as clear authority by the Security Council for the presence of British forces between the limiting dates in the charges faced by the defendant, namely 1 June, 2005, and 12 July, 2005."
The judge advocate said he did not believe the question of the legality of the invasion of Iraq in 2003 was relevant to the court martial, as it predated the charges.
He said: "It follows that it is unnecessary for me to decide whether the presence of British troops at an earlier date was lawful or not."
In last week's hearing, Mr Sapsford argued that his client refused to return to Iraq because he did not want to be complicit in a crime of aggression.
But the judge advocate said: "The law, it seems to me, is clear. The crime of aggression, even if it were a crime of which the domestic courts of the United Kingdom would take cognisance, cannot be committed by those in relatively junior positions, such as that of the defendant.
"If a defendant believed that to go to Basra would make him complicit in the crime of aggression, his understanding of the law was wrong.
"I conclude, therefore, that there can have been no illegality in the defendant obeying any of the five orders he was given, which form the subject of the charges.
"All five orders had a specific service purpose and all were therefore lawful orders."
He added that Flt Lt Kendall-Smith could not be considered liable for the crime of aggression because he was not a leader.
Mr Sapsford told the judge advocate that his ruling "provides a number of hurdles for the defendant to overcome".
A spokeswoman for the Ministry of Defence said that it had noted yesterday's ruling, and added: "It would be inappropriate to comment further until after the outcome of the court martial hearing."
The court martial trial will take place in Aldershot on 11 April. It is expected to last about three days.