Unfortunately, SWISH doesn’t allow for unconstrained asserting of terms as that can break the required isolation and sandboxing of user queries. You can assert, but only to predicates known at compile time. Thus, assertz(p(X,Y)). is fine.
Probably a little redesign can help to make this possible. Otherwise you can only use a local installation of SWI-Prolog or a locally deployed SWISH where you can disable the sandboxing.