A rogue Afghan police officer opened fire on British soldiers, killing five and injuring six, after a row over a hat he turned up in for duty, an inquest heard.

The man, known only as Gulbuddin, shot soldiers who were mentoring Afghan police officers at a checkpoint in Helmand province. Earlier in the day he had turned up in a "brown Afghan hat" and went off "in a strop" after being told by a British soldier to wear his police issue headgear.

The inquest heard claims that Afghan police officers were open to corruption, sometimes lacked commitment and were high on drugs while on duty. In one episode outlined during the hearing an Afghan police officer gave ammunition to the Taliban in exchange for narcotics. It also emerged that the British men were posted at the checkpoint after a "blood feud" between an Afghan police officer and a local Taliban commander.

Lance Corporal Liam Culverhouse, who was shot in the eye in the attack, told the inquest at Trowbridge in Wiltshire that he was reading a magazine when the shooting began and saw a "flash of red". "I realised I'd been shot. I heard a rifle going off in automatic bursts and Gulbuddin shouting something that was like a war cry. I felt the pain and my eye was blind."

"Gulbuddin was screaming. I decided it was time to get out of there so I crawled around the corner and I decided to play dead, close my eyes and hold my breath. All I could hear inside was gunfire, scream, gunfire, scream. From then on I fell unconscious for a period of time. What woke me up was a helicopter going past."

Gulbuddin fled and his motives remain unclear, but Culverhouse described how on one occasion the Afghan police officer had grabbed him by the head and on another had "barged" him off a platform. "It wasn't just me. He was always trying to wind up members of the platoon and he had been warned about his behaviour," Culverhouse said. "The police at the checkpoint were a ragged bunch."

On the morning of the shooting he turned up for a patrol not wearing his police hat. He was told to wear his uniform. "He went off with a little strop on, rifle over his shoulder," said Culverhouse.

Warrant Officer Class 1 Darren Chant, Sergeant Matthew Telford and Guardsman James Major, all of the 1st Battalion Grenadier Guards, died alongside Corporal Steven Boote and Corporal Nicholas Webster-Smith from the Royal Military police on 3 November 2009. The men were "relaxing in the sun" at Blue 25 checkpoint in the Nad-e-Ali district and were not wearing body armour or carrying weapons.

Lieutenant Colonel Charles Walker, commanding officer of the 1st Battalion Grenadier Guards, insisted the Afghan police force was full of men determined to do good for their country. But he said that Blue 25 had been beset by problems when his troops arrived in the area. A shura – meeting – was arranged with village elders and it was discovered that there was a blood feud between the local police officer in charge of Blue 25 and a Taliban commander.

Walker decided to use his own security detachment – which usually helped guard him as he moved around the area – to mentor the local police at the checkpoint.

Questioned by the Wiltshire and Swindon coroner, David Ridley, Walker accepted there were problems within the Afghan police force, giving the example of a checkpoint commander who traded ammunition for drugs with the Taliban. He said some of the officers later got high on the drugs and their police station was attacked by the Taliban that day.

Walker said such a series of events was "not untypical". He said Afghan police officers were poorly paid and so were "susceptible to the influence of money".

Walker told the inquest that after the shooting he made a number of recommendations including setting up separate recreation areas for British and Afghan men and making sure rest areas were better protected. He also suggested that sidearms were carried as a deterrent against "irrational action".