Joseph Kelly, 36, posted on Twitter that “the only good Brit soldier is a deed one, burn auld fella buuuuurn” on February 3 last year.
Kelly, of Castlemilk, Glasgow, was found guilty of sending the message following a trial at Lanark Sheriff Court in January and returned to the court for sentencing on Wednesday.
Sheriff Adrian Cottam told Kelly he passed the “custody threshold” but there is a presumption against prison if there is an alternative.
He sentenced him to a community payback order comprising 18 months of supervision and 150 hours of unpaid work, and said the punishment should act as a deterrence to others.
Sheriff Cottam said: “My view is, having heard the evidence, that this was a grossly offensive tweet.
“The deterrence is really to show people that despite the steps you took to try and recall matters, as soon as you press the blue button that’s it.
“It’s important for other people to realise how quickly things can get out of control.
“You are a good example of that, not having many followers.”
Kelly’s defence agent Tony Callahan said the 36-year-old had only a handful of followers when he posted the tweet and did not realise how widely it would be shared.
He said Kelly quickly took steps to take down the tweet, which was only live for 20 minutes, and has since expressed regret and remorse.
Mr Callahan said: “He accepts he was wrong. He did not anticipate what would happen. He took steps almost immediately to delete the tweet but the genie was out of the bottle by then.
“His level of criminality was a drunken post, at a time when he was struggling emotionally, which he regretted and almost instantly removed.”
The charge under the Communications Act said Kelly made a post to the public using social media that was “grossly offensive or of an indecent, obscene or menacing character, and that did utter offensive remarks about Captain Sir Tom Moore, now deceased”.
Sir Tom, who captured the hearts of the nation with his fundraising efforts during the first coronavirus lockdown, died in Bedford Hospital on February 2 last year after testing positive for Covid-19.
He walked 100 laps of his garden before his 100th birthday, raising more than £32 million for the NHS, and was knighted by the Queen in recognition of his efforts.
After Kelly was found guilty at the trial, Sheriff Cottam told him Captain Tom “is a man who had become known as a national hero, who stood for the resilience of the people of a country struggling with a pandemic and the services trying to protect them”.
He added: “His statute and the view of society towards him must be looked at in that light and therefore any comment likewise.
“What the accused chose to write, when and how it was said, can only be regarded as grossly offensive.”