To perform some activity, typically IT related, where performing the activity gives the performer near sexual pleasure while doing it, yet nothing of any value or lasting value is produced. Mental masturbation is reasonably acceptable in the privacy of the performer's home, where their time is free (in money terms), but not on their employer's time. Mental masturbation can be the cause and reason for overly complicated and hard to understand IT solutions being implemented in one company, despite simpler, more commonly understood and tried and tested solutions to the same problem being used at a number of other companies in the same industry.
To workmate, on Monday morning, "Guess what I did over the weekend! I rewrote Linux in FORTAN! Cool huh! Next weekend I'm going to rewrite it in COBOL!"
Workmate, unimpressed, "That sounds like mental masturbation to me."