Forward hooks can be registered to modules and if you are using calls from the functional API in the forward method, e.g. as seen here, the intermediate activation will be manipulated.
In the liked case the activation will be flattened, which would yield the shape mismatch error.