Depends on the country. There might be visa requirements to enter it.
Ukrainian citizens are no longer allowed to leave freely. Men are not allowed to leave, that seems to be confirmed. According to some sources women working in certain sectors like health care either, not sure whether that is confirmed.
Normally at a border you have guards from both countries . First you need to leave one country and then you can enter the next one. I have no idea how effective Ukrainian border guards are. Until last week they were not needed for this purpose.
First of all, the policy is Ukrainian one, the Poles are taking in practically everybody with an Ukrainian passport, it would be inhumane no to do so.
But Ukrainians are understandable too, and some men are allowed to leave. On the other hand, there are also some returning home from Poland. Imagine you went to Poland in order to provide for your family and your family is left at home. There are many cases like this. In such a situation going back is often the only option - staying away would only cause constant suffering with you being anxious if your wife and kids are safe at that moment or not, and frantically reading all reports of bombing and civilian casualties.
Ukrainian citizens are no longer allowed to leave freely. Men are not allowed to leave, that seems to be confirmed. According to some sources women working in certain sectors like health care either, not sure whether that is confirmed.