Assign IDs to headings in ACF using functions.php

How are you printing the contents of the ACF field in your site code?

Assuming that you have self-coded theme files, instead of using the_field() to print the field content, you should echo get_field() passed through the 'the_content' filter,

eg: echo apply_filters( 'the_content', get_field( 'my_field_name' ) );

and it will apply the modifications from your first snippet.