Q:

I have no magic weapon; why might I melee a target who is immune?

Let's say I have a character with a non-magical weapon, and I find myself in melee with a target immune to non-magical bludgeoning, piercing, and slashing damage. 
What reason might I have for making a melee attack instead of disengaging?
This question was prompted by recent discussions about sneak attack and smiting with respect to immunities.

A:

Obviously, as noted in a comment, the character might not know about the immunity. But if she does:
Immune to taking damage doesn't mean immune to being hit, and some features trigger (or become available) when you hit, regardless of doing damage. Examples:

Some spells, like Bestow Curse, Hex and the various Smite spells.
Some class features, including: Divine Smite; Divie Strike; Hurl Through Hell; Quivering Palm, Raging Storm; Relentless Avenger; Sign of Ill Omen, Stunning Strike; Totemic Attunement (Wolf); Touch  of Death; Unwavering Mark; and many of the Battlemaster Fighter's maneuvers.
Some feats, like Sentinel and Tavern Brawler.
Barbarians below level 15 need to attack to maintain rage.
Non-weapon attacks like shoving or grappling can be used.

Note that features like Hexblade's Curse would not add damage to the initial melee attack, but would trigger on additional damage from something like a Smite.
Also note that there may be tactical reasons to stay engaged without taking the attack action, including: assisting to give advantage to another character; allowing another to Sneak Attack; and being the target for attacks so that others aren't.

A:

There can be many reasons to perform a melee attack
The obvious ones are for effects like a Paladin's Divine Smite that key off of hits and not damage. Others, like a Level 14 or less Barbarian's Rage (Thanks MivaScott!) require either being damaged or attacking in order to maintain the rage and gain those benefits.
The less obvious can be around battlefield control. Contests in Combat such as the Grapple or Shove are special melee attacks and qualify as melee attack options. They can help control the battlefield and the creatures on it.
Even less obvious is to act like a traditional tank. Keep the enemy engaged with you while your other party members use their more effective attacks to take it down. Be the meat shield you always wanted to be!

