Keras does not require y_pred to be in the loss function. Though, it needs that all trainable variables to be referenced in the loss function.
When you call this function: m3.fit(), Keras will perform a gradient computation between your loss function and the trainable weights of your layers. If your loss function does not reference the same elements that you have in the trainable_variables collection, some of the gradients computation operations will not be possible.
You can avoid it by referencing y_pred, even if doesn't do anything. Or you could halt the layers that won't be impacted by the optimizer (as you don't compute their loss anyway)
So in your case, you just have to halt your output layer :
output = Dense(1, trainable = False)(hidden_a)
If you wish to know more about Keras then visit this Python Course.