I’m assuming from your question that the “gallery” is not created on the page in question and is created somewhere else since checking the field will let you add it to any page. If this is the case then you need to supply ACF with the post ID of where the gallery is stored, whether that be another post or on an options page.
$images = get_field('gallery', $post_id);
For more information see the documentation for get field https://www.advancedcustomfields.com/resources/get_field/, especially the part about getting a value from different places.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!