Yes. You can walk out of the ER without being discharged. For example, you may come to the ER and find every bed filled, the staff running around, and face hours of waiting in the emergency waiting room. If you feel overwhelmed, you can simply leave without being discharged.
It is normal to feel concerned about catching something else in the ER waiting room, especially in these days when a coronavirus may infect every person you meet.
If you don’t want to wait for hours, you are free to consider other places where you may get help. The emergency room staff may ask you to stay, but they cannot keep you in the ER against your will.