Custom function in My Custom Functions returning 403

You can use wp_head. This will insert the script in the head.

function dropin_location() {
    if ( is_page( 7 ) ) {
        ?>
        <script>alert('got here')</script>'
        <?php
    }
}
add_action('wp_head', 'dropin_location');

However, there are other ways to add scripts. You can have it as a script file in your theme and enqueue it so that WordPress “knows” about it. This way it can have dependencies, load at the correct time, etc. Here is an explanation.

So if you have my-killer-script.js in your theme, you can do the following:

wp_enqueue_script(
        'some-script-handle', // some name to give it
        get_theme_file_uri( '/path/to/my-killer-script.js' ), // file path to script
        array( 'some-dependency-handle' ), // does this script need any dependencies? If so, add their handles, or leave the array empty.
        false, // do you need a version?
        true // load in footer? true/false
    );

Read the WP docs on wp_enqueue_script here.