Note: This answer was originally crafted for this now-closed-as-a-duplicate question that asked about preventing magical interference with court business and magical courtroom procedures, both preferably involving only low-level and mid-level spells.
Order in the court
A serious courthouse should be affected in its entirety by the 6th-level Clr spell forbiddance [abjur] (PH 232-3) tied to a clearly visible, respectable, unembarrassing password. Even with the password present, creatures still can't employ extradimensional movement methods (like teleportation effects) to exit or enter the courthouse. (The password prevents damage upon entering the courthouse mundanely; nothing allows extradimensional movement into, out of, or within a forbiddance effect!1) (Tying a dimensional anchor effect to, for example, a hallow effect likely only inhibits a creature that's using extradimensional movement from exiting that way and traveling that way within the affected area but not from entering the affected area using a teleportation effect!) (Also see this question.)
Notices should be posted around the courthouse that unauthorized magic items will be confiscated upon entry. To enforce this, I'd expect the court to employ at least one extremely trustworthy or magic resistant creature on whom the 0-level Sor/Wiz spell detect magic [div] (PH 219) has been made permanent through the use of the 5th-level Sor/Wiz spell permanency [univ] (PH 259-60) and that possesses significant ranks in the skills Knowledge (arcana) and Spellcraft. (In a pinch, a level 2 warlock, a level 7 swordsage, or a creature capable of employing a wand of detect magic (0-level spell at caster level 1) (DMG 246) (375 gp; 0 lbs.) will do instead.) That creature is equipped with an artificer's monocle (Magic Item Compendium 72) (1,500 gp; 0 lbs.) that the creature employs to use an identify effect on any magic items.
In addition to identifying all of a creature's magic items, the creature itself should be subject to a detect magic effect and all magical effects operating on the creature successfully identified. Paranoid courts will insist that a creature repeatedly trigger until no magic remains an automatically resetting boon trap of greater dispel magic (PH 223) (6th-level spell at caster level 20) (Dungeonscape 135-6) (60,250 gp; architecture).
Obviously, unauthorized creatures should be prohibited from casting spells in the courthouse. Baliffs should have significant Spellcraft skill check modifiers and each should wear a ring of spell battle (Complete Arcane 144) (67,600 gp; 0 lbs.). Circular courtrooms become the norm as they should be designed so that no one can be more than 60 ft. from the ring wearer. (The ring is the most expensive element of courtroom security; a DM may consider homebrewing a lesser ring of spell battle that lacks the original ring's counterspell-or-redirect property, likely substantially reducing the item's cost.) This still won't prevent magical terrorism, but that's really difficult anyway without each courtroom bearing sigils of antimagic (Stronghold Builder's Guidebook 83) (66,000 gp; architecture), and those create a whole 'nother set of problems (like—ew!—totally mundane courts!).
A super paranoid court may also, every hour, confirm officials lack bias by using a rose of kings (see below). (Such a court will also likely want automatically resetting boon traps of cure minor wounds (PH 216) (0-level spell at caster level 1) (Du 135-6) (750 gp; architecture) and neutralize poison (PH 257) (4th-level spell at caster level 7) (Du 135-6) (17,500 gp; architecture) unless the court is willing to risk court officers being disabled, drunk, or both.)
Handling the truth
Both the 2nd-level Clr spell zone of truth [div] (PH 303) and the 4th-level Clr spell discern lies [div] (PH 221-2) are unreliable methods of getting at the truth. Even employing the 3rd-level Clr spell speak with dead [necro] (PH 281) for maximum efficacy typically mandates the court keep on hand several different casters of wildly divergent faiths, making consistent and frequent use of the spell difficult in all but the most tolerant of societies.
(For 3,000 gp per year the spell zone of truth can be tied to the effect of the 4th-level Clr spells hallow [evoc] (PH 238) et al., but tying a zone to the hallow effect does not eliminate the zone spell's saving throw, and the zone spell's caster receives no feedback if a creature succeeds on the saving throw against the zone effect, the effect affecting an area.)
I wouldn't expect the 1st-level Clr spell detect good [div] (PH 219) et al. to be used by the court with any regularity to reach conclusions during regular proceedings: even good creatures break the law, after all! However, the court might allow a creature whose alignment is confirmed by a detect alignment spell to have that factor into the creature's sentencing. But the detect alignment spells are remarkably easy to spoof, even mundanely—for example, with the feat Mask of Gentility (Elder Evils 25-6) or Mind Mask (Secrets of Sarlona 117). I suspect larger courts favor evidence and honest testimony, ignoring a creature's alignment altogether.
Because of the limitations of the aforementioned spells, this GM recommends the court invest in the rose of kings (Dragon #289 106) (10,000 gp; 0 lbs.), a "chalice of copper or, rarely, wood in the form of a beautiful rose" with, on its stem, sharp thorns, one of which glows green when the rose is filled with wine. A creature that touches the glowing thorn is dealt 1 point of damage; this also causes one of the rose's twelve petals to glow. Each creature that's dealt damage by a glowing thorn and that subsequently drinks from the rose is for 1 hour unable to lie to other creatures that've also been dealt damage by a glowing thorn and that've subsequently drunk from the rose. Creatures subject to the rose's effect can lie freely to those who've not undergone the prick-then-drink process, and creatures are not compelled to speak. Presumably, the maximum number of creatures that can be involved simultaneously in a rose's circle of truth is twelve (the number of petals on the rose), but this is only implied by the text.
Thus a typical rose of kings trial by jury may include the accused, the accuser, one lawyer for each, the judge, and a seven-creature jury. With all of them unable lie to each other, after a few insulting stock questions to confirm a properly functioning rose ("Are you a cheeseburger? To the best of your knowledge, will your behavior during this trial be influenced—magically or otherwise—by one or more creatures or forces outside this courtroom? How many fingers am I holding up?"), guilt or innocence should be established well within the rose's 1-hour time frame. (And it had better be—a level 1 commoner jurist that has a Constitution score of 10 will be rendered disabled by a second prick from the rose's thorn!) Such a trial can still find a guilty creature innocent (and vice versa), but that requires obfuscation, omission, calculated silences, and, possibly, a particularly careless judge or a really good attorney.
A rose's creation prerequisites are the feat Craft Wondrous Item and the spell zone of truth, making it so a rose can be created in 10 days by level 3 cleric possessing the appropriate feat (or with help from another who does); a community that's at least the size of small town has a level 3 cleric (Dungeon Master's Guide 137). The rose's price makes it available for purchase in any community that's at least the size of a small city (ibid.).
So far as I'm aware, the rose effect is the only surefire method of making a creature that's willing to speak actually speak truthfully, all other effects granting the creature a saving throw. The rose effect should even work on creatures immune to mind-affecting effects (as the rose's effect is not called out as a mind-affecting effect), and the GM may rule that the effect even affects creatures immune to divination and similar effects like from the 3rd-level Brd spell glibness [trans] (PH 236), the 8th-level Sor/Wiz spell mind blank [abjur] (PH 253), or the supernatural ability cloak of mystery granted by the template Vecna-blooded (Monster Manual V 66-7) (as the rose's effect isn't called out as a divination effect either, despite needing the spell zone of truth for its creation.)
While the rose's effect ensures that creatures are at the time speaking the truth, this doesn't mean they'll do what they said they'll do later. For example, a judge that asks the accused, "If convicted, do you plan to escape from prison?" may receive an at-the-time honest No, but that answer may change after the convicted elf's 213th year in prison without parole, for example. To make an judgment binding, I suggest the courts use contracts of Nepthas (Complete Arcane 148) (1,400 gp; 0 lbs.), the 5th-level Clr spell mark of justice [necro] (PH 252), or the 6th-level Sor/Wiz spell geas/quest [ench] (PH 234-5).
Like this fine answer recommends, a caster can employ the 5th-level Clr spell commune [div] (PH 211) or the 5th-level Sor/Wiz spell contact other plane [div] (PH 212-3) to determine a creature's guilt or innocence, but, "'[u]nclear' is a legitimate answer [to a commune spell's question], because powerful beings of the Outer Planes are not necessarily omniscient," and using the spell contact other plane to ask a question of even a greater deity yields a chance that the deity admits to not knowing an answer (2%); lies about the actual answer, presumably giving the opposite answer (9%); or makes up a random false answer (1%). (And whether these are better odds than the traditional courts is a question for another stack!) Finally, unless the deity that was posed the question deigns for some reason to answer aloud, only the spell's caster receives the answer! This is fine in the hands of, for instance, an incorruptible judge, but otherwise transparency may be an issue.2
1 Fine, there is the 8th-level Sor/Wiz spell freedom of passage [abjur] (Polyhedron #159 12 from Dungeon #100), but, c'mon, that's pretty darn obscure and, anyway, you don't have the spell's focus (at least not for very long you won't!).
2 The untyped feat Prophet of the Divine (Power of Faerûn 49)—one of my personal favorite feats—addresses this issue by having the deity answer some divination spells "in the form of a loud booming voice accompanied by a visible manifestation of the deity’s power, such as a nimbus of colored light in a hue favored by the deity." Take that, haters!