Law defines a court of law
A court is a legal construct. Like a government department, a corporation, an army, a police force, or a fire department.
For example, the US Supreme Court is defined in Artice Three of the US Constitution:
The judicial Power of the United States, shall be vested in one supreme Court, and in such inferior Courts as the Congress may from time to time ordain and establish. The Judges, both of the supreme and inferior Courts, shall hold their Offices during good Behaviour, and shall, at stated Times, receive for their Services a Compensation which shall not be diminished during their Continuance in Office.
Other US Federal Courts that "Congress may from time to time ordain and establish" are defined in the laws that do that.
State Constitutions and laws define the various state courts.
The court building is more accurately described as a courthouse - a home for the court - but "court" can refer to the building.
A properly appointed judge can "hold court" wherever they like in accordance with the rules, but they usually use the courthouse because that's where they keep their stuff. Plus, they get a parking place, a furnished office, and often a private bathroom.
Historically, Federal judges would use the local courthouse when they rode circuit; however, the Federal judiciary now has its own courthouses, so they don't do this anymore. However, there is no law preventing them from doing so with the permission of the building's owner (the state or county)