Check session variable before delivering cached page

>All I want to do is make sure that for EVERY request (no matter if the page user wants to visit is cached or not) there is a simple check before that just looks at the session and checks if a certain variable is set.

It is impossible, in case page is cached - request fetched cached data without handling.

>If the variable is not set, the user should be redirected to a „custom login“ page where he can submit a form that will in turn set that variable in the session.

Is it some specific page?

Is it some specific customer groups?

Can you describe more details, maybe I can propose some solution.

>Do you think implementing it as a widget can solve that?

No, for such cases widget isn’t solution.