when an iMac is in a Sleep Mode , And a UPS is connected , what happened if a Mains failure occurred ?
As far as the Mac is concerned, absoutely nothing.
A sleeping Mac uses about as much power as a night light. Depending on the specific model UPS you choose, it will continue to sleep, on UPS power, until the UPS battery dies. This could be eight to twelve hours.
Does the iMac need to be protected when it in a sleep mode ?
A UPS conveys at least two specific benefits: power conditioning, which addresses poor power quality (e.g surges, sags, dropouts) and backup power so as not to interrupt your work if the power disappears for brief periods of time: minutes, not hours. Most consumer grade computer UPSs are intended to keep your equipment powered long enough for you to save your work and then shut down your Mac, rather than have unsaved work disappear.
A Mac deprived of power will lose unsaved work whether it is sleeping or not. However, it is worth pointing out that most new Mac apps (such as Notes and Pages) automatically save your work so this has become less of a concern recently. Apple seems to be designing their products, both hardware and software, with a goal that the user should not have to be burdened with the tedium of periodically saving work.
As far as "protected" goes, a UPS's power conditioning holds true even for a Mac that is "shut down". The problem with most consumer electronics these days is that almost nothing has a real power switch any more - nothing to separate it from mains power, as long as it is plugged in. Therefore a Mac that is plugged in but "off" is still connected to the mains, and exposed to potential damage from nearby lightning strikes that can dissipate energy through electrical wiring. A UPS provides a degree of protection from that threat, though it by no means absolute.