Limping is a weak move, no doubt, but here are a few situations where limping might just be the optimal play.
When other people have limped in front of you.
Limping is a passive, weakish play that is not an enriched play by many of the books you'll read on hold'em. However, there are times where limping is an acceptable play, and one of the best times to do so is if other players have already entered the pot in front of you via the limp. This is when you can play your drawing hands like 45s, 67o, J8s, with multiple players in the pot and an increased chance of being paid off when you make a hand with these special hands. It also makes it harder for a player behind you to make a raise that narrows the field; the amount needed to raise increases with every player that limps, so a player that may normally open with 99 or AQs may elect to simply flat call with 4 players limping in, giving you even more of an edge against those strong, but vulnerable hands postflop .
When you're the button and it's folded to you.
If the blinds have been relentlessly defending their blinds via calling or three-betting, you may choose to include a few limps to vary your play and see flops cheaply against them with hands that rate to play well against their aggressive range. It also allows you to limp / raise with hands you would normally raise / fold with, giving you an extra dynamic to utilize against the blinds. Limping can also be acceptable if the players in the blinds are tenacious in their tendencies to see a hand to the river; you can see cheap flops, and when you hit the flop, make larger than average bets that your opponents will dutifully pay off left and right, where they may have folded preflop. Or, they may call and not release to your continuation bets, making them unprofitable bets when you've raised preflop. By controlling the pot size via the limp, you angle yourself to making profit postflop decisions against bad players.
When you're in early position and you want to mix your game up.
UTG and UTG + 1 are the toughest positions in the table, and demand respect when a player enters the pot from these positions. If you're reliably deep stacked, you can use UTG play to limp with monsters and speculative hands both, though not very frequently. You may choose to limp with AA / KK / J10s only, and always three bet when someone raises after you limp. By mixing in a single speculative hand in with your monsters, and being able to show down the specific hand if you win the pot, you put the thought in your opponents head that you do not always have premium holdings when you play a pot from early position, which may garner more action when you do limp / raise from UTG; people will remember you showing down a connected suited hand after a preflop limp / raise just as much as they will aces.