Swansea magistrates said Robert Riley's online messages were also racially and religiously aggravated and that only a custodial sentence could be imposed.
Riley, from Port Talbot, was sentenced to eight weeks in custody after admitting posting an abusive Twitter message about the death of Leeds schoolteacher Ann Maguire.
The 42-year-old was the second person to be charged with the offence in the wake of the death of Mrs Maguire, who was stabbed to death in her classroom at Corpus Christi Catholic College last month.
Yesterday a third person was arrested in Cardiff and bailed.
More top news
Astronaut Steve Swanson has been working with schoolchildren from across South Wales, as part of a special space science project.
It's the home of the world's first mail order company, with links to Queen Victoria and Florence Nightingale, and now it could be yours.
Rail users in Wales could be hit by disruption later this week after talks to avert a 48-hour strike broke down.