If people agree to automatically buy a ticket when entering a train, the law would never apply, since they always had a ticket.
You already agree to buy such an ticket (at the "erhöhtes Beförderungsentgelt" price) but there is no way to avoid a criminal law specifically designed for that situation by just changing the content of a contract.