They both mean court and can be used to talk about court/the courthouse. BUT the following are the more natural usages.
If I said I’m going to 법정, that means I’m going to a trial, I’m on trial, I’m a witness, or something of the sort.
This is more general ‘court’ and can also be used to refer to the courtroom itself.
If I said I was going to 법원 then I’m going to the courthouse in general. It generally insinuates that I’m going to the building itself, or a place bigger than just the courtroom.
This is ‘courthouse’, or the building itself.