As usual, I would not go to my boss with a "problem" but with a "solution".
Hi [ boss / manager ], I have a very important appointment at xx PM (1). Would it be OK to work [ earlier / later / best for your team ] so that I can leave for a couple of hours with no negative impact on [ X - Y schedule / task ] ?
If you have a negative answer, because your solution doesn't fit their needs, ask them how you could achieve the same goal with benefit for both sides.
I would not tell them anything personal (court or wathever else it could be). It's private, so keep it private. If you know you'll have to go once or twice more, tell them you have some other scheduled appointments ASAP, with days and hours.
Just be professional, ask them in a nice, neutral and professional way.
They'll handle it with the team. It seems to be a one-shot, so no need to worry that much, and make a big deal out of nothing. Of course, keep track and a paper/mail of the agreement ;)
(1) you can also mention that you forgot to tell them earlier, and apologize for it. It depends on the company culture and/or boss attitude, but you should have small clues by now, after 2 weeks, on how you can handle/approach them.