(Note: the following information I know is true of the small parrot/parotlett/lorrie/budgie/parakeet species, I believe it holds true to most birds but I am not sure.)

"Mastrubation" is a very common phenomenon in birds, actually. The female of almost *every* species produces eggs on a natural cycle. It's part of the natural biological cycle necessary for reproduction. Human females don't need a mate to ovulate. This is much the same thing.

In a bird's case, their bodies will go into the state where they *can* produce eggs-and they always *start* to.  But the egg will not finish forming unless the circumstances are favorable for fertilization and successful hatching. Not guaranteed, just favorable, in terms of temperature, lack of predators, environment, possibility of nesting materials available, time of year and so forth. The current presence of a mate is not in this criteria, because in the wild few birds are monogamous. They merely look for a mate right at the time of fertility. "No male in my cage today means no male in my cage next week" does not make sense to them.

If the bird's instinctual pattern decides "no, this is a non-favorable time to raise hatchlings", or a time where the eggs will most likely not hatch, her body re-absorbs the partially formed egg. Producing a completely unviable egg is a strain on her body, as it depletes her calcium supply quite badly. If there's not much chance, she doesn't bother, and instead conserves her resources for her next fertile time.

However, if conditions are favorable enough for her to continue to form the egg she will. Said egg remains viable for X amount of time, depending on species. If it's fertilized by a male, great, it gets laid and hopefully hatched and raised. But if it is not fertilized, she must get the fully-formed egg out of her body anyhow, or risk serious health problems including calcification of the egg (this drains all her calcium supplies), impaction of the egg, breakage of the egg inside and resulting cuts, or various forms of internal poisonings. Since this egg already exists, she *will* lay it, male or not around. His presence has nothing to do with the egg being laid, only fertilized.

As for the 'masturbatory' behavior, many birds indeed do this. They *can* lay the egg without it, but it is very stressful on their bodies, equivalent in terms of size as giving birth to a full-term baby or litter is for mammals. So anything they can do to trigger muscle contractions to aid them, they will.

additional note: sometimes birds will produce eggs anyways if circumstances are unfavorable if they have other health problems. Hyperactive thyroid is one of the most common causes of excess egg production. This, and other hormonal imbalances, are the reasons some birds seem to produce eggs constantly instead of just occasionally.