There is no way to avoid Doktor Stein, but you can be ready for him.
The pill in the medicine bottle is the antidote.
Before you are arrested you must be holding the pill.
The first turn, and I mean the very first turn, after being thrown in jail, you must eat the pill. This will neutralize the poison.