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
A woman who refused to get married as a 'fat bride' tells GMB she shed six stone after a nasty jibe about her weight left her in tears.
More than 200,000 women are screened for cervical cancer in Wales every year, but what exactly is it they are being tested for?
Five young sailors from South Wales will be training in Pwllheli this morning ahead of the Optimist European Championships.