You most probably used the theme location part wrongly. Here is an example of how it should be done
Follow the comments in code for explanation 🙂
add_filter( 'wp_nav_menu_args', function ( $args )
{
if ( is_page( 2 ) //Only target page 2
&& $args['theme_location'] === 'primary' ) { // Check and only target the primary menu
) {
$args['menu'] = 'Menu for Profile';
}
return $args;
});