Hello,
The problem you describe is common with the earlier iMac G5 systems. There is a mesh / sweep on the edge of the CD-Drive slot. This sweep slows the ejection, and prevents the power from kicking the disk out too far.
And, as that wears down, this problem becomes more common. If your machine is under warranty, then call Apple and request them to fix this problem. It will likely return again in the future, but if it's under warranty, I'd get it fixed and perhaps it will take longer to break-down again.
I've seen this on my own iMac G5 systems.
If the machine has been recently serviced, then it's also entirely possible that they just didn't get things lined-up right. I've had that problem as well and the CD would just spit-out after the drive had been removed and re-installed as part of another repair.
So, if it's under warranty, get it fixed. If it's not, then hold your hand there when you eject a disk to prevent them from falling and getting scratched.
I hope this helps.
Let us know if you have other questions.
P.S., if you'd like, go ahead and click the "Helpful" or "Solved" buttons on any of the posts / replies above if you feel they were helpful or adequately answered your question.