The UK is a constitutional monarhy. Thailand is also a constitutional monarchy. However, the constitutional monarchy in Thailand is not like what one'd expect in the UK. In the UK, Parliament is supreme. The Monarch in Parliament reigns and exercises royal prerogatives through the Prime Minister who must have support of Parliament.
In Thailand, the armed forces don't answer to the Defence Minister or even the Prime Minister. They can exercise powers in the name of the Monarch too, just as Parliament exercise powers in the name of the Monarch. The Thai armed forces can declare war on a foreign state without going through the government, and can also refuse to act on a declaration of war if the generals are not satifsfied that the government has made the right call. The army's loyalty is to the King and it's duty is to keep the borders intact and the system functioning within the borders.
Singaporeans accustomed to our Westminister-derived system may wonder, how can the Thai armed forces do that to the government? Don't they rely on the government for their appointments, salaries, promotions and budgets? The answer is that they don't.
Imagine the CCP and the KMT in China before 1949. Both sides were supposedly political parties, but fighting with bullets instead of ballots. The difference with Thailand here was that, both sides in China then were armed.
In Thailand, the armed forces didn't become a political party, but retained certain political and discretionary powers. The elected Parliament represents the Monarch through election. The armed forces represent the Monarch through residual convention, backed by some real financial muscles of course. It's common knowledge that Thai army and police chiefs have stakes in many businesses, just like many businesses in China are still owned and controlled by the PLA.
The PLA pledges allegiance to the CCP and the PRC, which are one the same. No problem there, nothing to coup about. However, the Thai military pledges allegiance to the Thai King, as distinct from the Thai Parliament. As long as civilian political winds blow their way, favourably and tolerably, life goes on.
What caused the 2006 coup was that most military leaders came to a point to decide that Thaksin's methods and policies had become intolerably threatening.
Look at it this way. In conventional academic terms of the separation of power among organs of state, there're the exceutive, the legislature and the judiciary. In Thailand, there're the executive, the legislature, the judiciary and the army. Whatever the army do, as long as the King doesn't publicly object or condemn, it's deemed to be in the name of the King, and therefore legitimate.