"Talking through one's hat" means "talk nonsense", especially on a subject that one professes to be knowledgeable about but in fact is ignorant of. This began life in the USA, in the late 19th century, with a slightly different meaning from the present one. It then meant to bluster.

To be allowed to make 'a point of order', which is an interruption to a previous speech in order to query something that had been raised, MPs had to be 'seated and covered'. That is, seated and wearing a hat. "Topping" was the name given to 'talking out' a bill, otherwise known as filibustering, by continuing to speak until debating time ran out. Having made a point of order and while wearing a top hat, an MP couldn't be interrupted and could continue talking for as long as he/she wished. Naturally, as these speeches often lasted hours, they were frequently filled with rambling nonsense.

More Info: www.phrases.org.uk