PyMC Compilation Nesting with pytensor.scan

You need to wrap that Scan inside a CustomDist, in order to define a PyMC model variable. This PyMC example may be useful: Time Series Models Derived From a Generative Graph — PyMC example gallery