Robert Riley regarded Twitter as a chance to engage in "social banter" but had "no idea" of the site's "vastness", magistrates in Swansea heard.
Riley's solicitor, Giles Hayes, said his client - a former bus driver who left school aged 15 with no qualifications - lived an insular life.
The court also heard a report from the Probation Service saying that Riley was a full-time carer for a 44-year-old woman.
"Because of this he has very little time for social activity out of the house," it said.
Mr Hayes described the tweet about Leeds teacher Ann Maguire as "a senseless act at a very sensitive time."
Magistrates were told that, since his arrest, Riley has sought help from counsellors over anger management issues.
His legal team admitted while his offensive comments pushed Riley past the custody threshold, the court could still impose a suspended sentence.
Mr Hayes said that would give the defendant the chance and the support to address his behavioural problems.
However, magistrates decided otherwise and Riley - dressed in a black shirt and trousers - was led down to the cells by two female security officers.
He hid his face as he was then led into a custody van and driven to prison.
More top news
Wales Captain Sam Warburton says his team are raring to go as they kick off their Six Nations campaign in Dublin tomorrow.
Liberal Democrat leader Tim Farron has criticised Labour at the party's spring conference in Cardiff.
A Royal Gun Salute was held at Cardiff Castle earlier today to mark the 64th anniversary of the Queen's accession to the throne.