Where helmet laws exist, getting stopped is usually an anticlimax: police issue an on-the-spot fine, typically modest, sometimes with the option to contest it later, and in a few places first-timers get a warning or the fine is waived on proof of buying a helmet. Countries with all-ages mandates and real enforcement, Australia being the famous example, do run periodic checks and fine consistently, while child-only-mandate countries direct penalties at the responsible adult. In the many countries with no adult helmet law, there is simply nothing to enforce on a regular bicycle, though e-bikes and e-scooters may carry separate rules that are policed.
Enforcement concentrates where riders concentrate: city centers, beachfronts, and tourist zones, and yes, visible foreigners on rental bikes get stopped like anyone else. Unpaid fines are not worth testing, since they can follow you through rental companies or, in some countries, surface at immigration on a future visit.
The dull but bulletproof position: know whether your destination has a mandate, which its road authority states plainly online, and wear the helmet regardless. It also matters after a crash, when injury claims and insurance assessments go noticeably worse for riders who were breaking a helmet law at the time.