How to change dynamically page title according to variable data?

Filters take variables from the function where they are defined. So, the Yoast plugin defines the wpseo_title filter inside on of its functions and passes a variable with it. You cannot insert your own variable.

However, since you are still in the same page build, you can still access the $_GET variables inside your own filter. So the trick would be to isolate the snippet from your first function in a third function, which you call from the second function as well. So, you don’t pass the variable, but construct it twice, making sure in this way that the same value is available both times. Like this:

function function1() {
  // your code ...
  $z123 = function3();
  // your code ...
}

function function2( $title ) {
  // your code ...
  $z123 = function3 ();
  // your code ...
}
add_filter( 'wpseo_title', 'function2', 10, 1 );

function function3() {
  $mainiid = $_GET['stattype'];
  $title_new = $_GET['titype'];
  $z123 = $title_new;
  return $z123;
}