Check the stored / cached WP_Query with transients on post change

Use the save_post hook to check if a post that is being saved is a portfolio page and reset the transient.

add_action( 'save_post', 'reset_portfolio_transient', 10,3 );

function reset_portfolio_transient( $post_id, $post, $update ) {
    // Only set for portfolio post_type
    if ( 'portfolio' !== get_post_type($post) ) {
        return;
    }

    // delete old tranisent
    delete_transient( 'randomizeProfiles' );

    // reset your transient
    set_portfolio_query_tranisent();
}

set_portfolio_query_tranisent() being the code you already provided.

If you edit portfolio pages often this is not a great solution. You might want to read the wordpress codex on transients for an alternative.