What are the consequences of an airline pilot deviating from a flight plan to perform a random maneuver?
As long as the pilots clear it with ATC and it doesn't violate the general rule against careless or reckless actions, there is nothing illegal about it. Pilots frequently request minor route changes, and ATC generally grants them if conditions permit. For instance, aircraft departing SFO often request a scenic pass by the Golden Gate Bridge as a treat for themselves and/or their passengers.

As long as no laws are broken (see above), their employer won't know whether the deviation was initiated by ATC or by the pilot, nor would they probably care even if they did know.

OTOH, if a pilot deviates from ATC instructions, it could potentially get them killed, so few pilots would knowingly do that. Deviations are almost always unintentional, and unless the pilot has a history of such problems that calls his qualifications into question, he/she will most likely get a "counseling" session and perhaps some refresher training.