Complete Warrior includes a mancatcher, an exotic weapon that can automatically grapple targets and has special rules for grappling at a distance (since it has reach).
It has always been my impression that, the mancatcher aside as a special exception, grappling required an unarmed strike, and could not be performed without a free hand. The definition of handedness notes that
A light weapon [...] can be used while grappling,
which strongly suggests that other weapons, like a lucerne hammer, cannot be. This is referring to the rule under grappling for attacking an opponent, which says
You can make an attack with an unarmed strike, natural weapon, or light weapon against another character you are grappling.
It also says
You can’t attack with two weapons while grappling, even if both are light weapons,
which again suggests what I was saying earlier about unarmed strikes, as does the simple fact that successfully grappling deals damage as if you had performed an unarmed strike.
Nonetheless, I cannot find any explicit mentions of a free hand being required for grappling, despite being fairly confident they existed. I will continue searching for that, but in the meantime, I only have this circumstantial evidence. After all, the mancatcher does more than just allow you to grapple with it, since it has automatic grappling and a fancy trip-like grapple option, and the “can be used in grappling” might just refer to attacking with the weapon, rather than just starting the grapple. So all this evidence is circumstantial, and could be explained a different way.
But if you are convinced, please note (as @HeyICanChan reminds me) that a character can perform an unarmed strike without necessarily using their arms or hands, so they can do it despite having weapons in hand. As @WannabeWarlock points out, this isn’t at all unusual in real life, either—leg-based takedowns while pummeling with arms and fists is a pretty typical move in mixed martial arts, for example. Doing it with armor and a big weapon in hand, okay, that’s harder, but these are fantasy heroes, so whatever. But the big, important thing here is, even if you do this, you are still using an unarmed strike. That means none of your weapon’s properties—like reach—apply.
If you are unconvinced, then the rules basically don’t really cover grappling-at-a-distance, so you’ll still have to houserule something. I suppose you could use the mancatcher rules, if you want, but that would seriously dilute the mancatcher’s value in my mind. Or you could just use the rules as-is, and ignore the weirdness where, for example, your character just instantly moves into the target’s space regardless of the distance between them.
Best Answer
I'm pretty sure what you want is to avoid the grapple in the first place. That's really hard because, for the most part, it's just a melee touch attack to start. So unless you're immune to being touched (possible but difficult) if you're immune to grapples before you know someone's going to grapple you, you're going to end up immune to attacks in general.
Assuming you don't want to play that game (the one, wherein, y'know, you're invulnerable to the mundane), escaping from a grapple is fairly easy, and, while harder, not getting grappled if you know it's coming is better. Here are ways of doing both. Omitted are sources providing effects under specific circumstances (e.g. in webs, underwater). The spells freedom of movement and heart of water included for completeness.
Spells
Best
Other Sources by Level
Many, many spells grant bonuses to grapple checks. If a creature can get a grapple check bonus high enough to just win the opposed check, he can end the grapple. I've not listed those spells. Many spells also grant a bonus to Escape Artist skill checks. I've not listed those either. I find the 2nd-level Sor/Wiz spell unfettered grasp [ench] (RDr 118) too situational to include.
Magic Items
Best
Other Sources by Price
Feats
There's only 1 feat you should barely consider if this is happening all the time, and that's the feat Close-quarters Fighting (CW 97). It's one feat, you'll meet the requirements, and if you've a spiked gauntlet (so you're threatening an area) you can make an attack of opportunity versus a creature that tries a grapple even if it has the special ability improved grab or the feat Improved Grapple (PH 95-6). Hitting it either stops the grapple cold or give you a bonus. You won't hit. You're a wizard. But 5% remains 5% and + something remains better than + nothing. Don't do this, though.
Your cohort, homunculus, intelligent animated dead, planar bound minion, or whatever, however, should take the feat Dutiful Guardian (DrU 50). Then you can rescue him (or not) while he's grappled instead.
Finally, if you're level 18 you can just take the feat Martial Study (ToB 30-1) and take the 5th-level Shadow Hand maneuver shadow stride [special] (ToB 80). Further, it has definite advantages as an extraordinary (rather than spell-like or supernatural) teleport ability. You can take the feat Martial Study at level 6 instead if an extraordinary teleport as a standard action is sufficient by picking the 2nd-level Shadow Hand maneuver shadow jaunt [special] (ToB 79)