If you are living in country you should be prepared to follow the rules and regulations of the country. If it is mandatory to remove the hijab while entering the court-room, either you don’t go there or don’t do anything that makes you go there. Any rule can be deemed to be discriminatory . A criminal might feel that rules are discriminatory. They are not made at the whims and fancies of some people. In Saudi Arabia you are mandated to follow the rules of the land.
Also you say that it was sad that she was arrested because she said something wrong before the judge. Well you dont expect the judge to be exactly humorous after hearing an expletive.
Another aspect is that the person did not have any qualms in uttering an expletive while showing herself as ultra -religious. Talk about Hypocracy …