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
The personal tragedies and triumphs that have shaped his life. Terry Yorath: Life on the Edge, ITV Cymru Wales on Monday, 23 October (8pm).
After support for her party fell despite an extra Westminster seat, Leanne Wood tells Plaid's conference it's time to reconnect with voters.
Police are 'urgently' searching for a father and his two sons who have been missing for nearly three weeks.