Are there any algorithms that learn to learn a function mapping?
This is equivalent to thinking of this as learning a function of two inputs, i.e.,  $g : (X,Z) \mapsto Y$ (i.e., $g(X,Z)=Y$).  Any machine learning method for learning functions can be used for that; you just treat the feature vector (the input) as the concatenation of the vector $X$ and the vector $Z$, and then use standard ML techniques on the resulting instances.  So, you don't need anything special or fancy to handle this -- you can use any existing machine learning method that you are comfortable with.