If the security situation changes, can I return to Ukraine?

Yes. However, remember that when you submit your application for international protection in Poland, you are obliged to deposit your passport with the Head of the Office for Foreigners. 

This means that if you decide to return to Ukraine while waiting for the decision on granting international protection, before you collect your passport, you will have to wait for a decision on granting protection / refusing to grant protection or cancellation (ending on your request or ex officio ) proceedings in the case. If you return to your country of origin after granting you refugee status / protection in Poland, the Polish Office for Foreigners will ex officio start proceedings to deprive you of such protection (assuming that – since you have voluntarily left for your country of origin – that is, that you no longer need protection from its authorities).