Police arrested a student who complained to them about receiving threatening messages after she used Twitter to say that people wearing Help for Heroes T-shirts "deserve to be beheaded" as news broke about the murder of Drummer Lee Rigby in Woolwich, a court heard on Friday.

Deyka Ayan Hassan went to her local police station after receiving hundreds of vitriolic responses to her comment on 22 May, hours after the soldier's death, including threats to rape her and kill her by burning down her home.

However, she was later arrested after telling officers that she had tweeted to her 600 followers: "To be honest, if you wear a Help for Heroes t-shirt you deserve to be beheaded." She said it was a joke about the design of the item of clothing bearing the name of the military charity.

The 21-year-old, who is studying English and politics at Kingston University, was ordered to do 250 hours of unpaid work, having earlier admitted a charge of sending a malicious electronic message.

Nigel Orton, the chairman of the bench at Hendon magistrates' court, told her she could have been jailed but that magistrates accepted she had not known it was a soldier who had been killed when she posted the tweet.

"The tragic events in Woolwich that day have created a context which made this tweet appear extreme," he said.

"It had a huge impact and clearly caused offence and distress. We accept you didn't intend to cause harm and you felt it was a joke.

"Your act was naive and foolish and without regard to the general public at a time of heightened sensitivity."

The court heard that Hassan's father worked in Somalia for charities including USAid and Prevent and was involved in combating extremism.

He was also described as a former associate adviser for policing diversity to the Metropolitan police.

The court heard that Hassan had sent out a tweet at around 4pm on 22 May, hours after Rigby was killed. At the time, rumours about the manner of the killing were circulating on social media, including unconfirmed reports that he had been decapitated.

Magistrates were told that she tweeted the message after seeing other people making remarks and had intended it to be a jokey criticism of the design of the T-shirt.

After receiving angry replies, she immediately closed her Twitter and Facebook accounts and went to a police station, where she was interviewed before being arrested.

Itpal Dhillon, defending, said Hassan had admitted that what she had written had caused "gross offence" and she was disgusted with herself, having been brought up to be tolerant and respectful.

"At the time she did not know the full details relating to the horrific incident," Dhillon said.

"She certainly didn't know that the man who was killed was a soldier and the killing may be motivated by extremist beliefs or values."