According to Ferrell (in this interview with the Toronto Sun), it was actually a prosthetic penis. He does, however state that a real penis was used during the rehearsals, implying that the scene was not a green-screen effect:
Taking the prison rape gag to new extremes, Darnell convinces James to
go to a gay bar and get a taste of performing oral sex on men. James
is hit on by a pushy regular (Matt Walsh) and taken into a bathroom
stall to get down to business.
Thing is, as wince-worthy as the scene may be for all the wrong
reasons, it’s very hard not to laugh at Ferrell reacting like a kid
who doesn’t want to swallow a dose of a particularly nasty medicine.
“It’s all a blur,” says Ferrell with a chuckle when recalling the
scene. “Let’s just say the prosthetic (penis) was only used when we
were going to shoot it.”
and in this interview (with professional prop-maker Matthew Mungle), we learn the process of how Ferrell auditioned the fake penis:
AVC: Was The Overnight the first time you’ve ever made a fake penis
for a movie?
MM: No, no. We’ve done We’re The Millers, Get Hard.
That’s a funny story because [for Get Hard] Will Ferrell wanted to
make sure it could be wiped in his face, because that’s what happens
in the film. And we sent him one that was a little too hard, so we
sent him another one, and a video of it. He rubbed it over his face,
and said, “That’s perfect.” It was soft enough. So then he sent it
back, and we painted it.