How to put distance restraints into topology file

One way is to add intermolecular interactions to your topology. See if Imposing restraints between protein and ligand and https://manual.gromacs.org/current/reference-manual/topologies/topology-file-formats.html helps.

The other alternative is to use the pull settings in the mdp file, see https://manual.gromacs.org/documentation/current/user-guide/mdp-options.html#com-pulling and https://manual.gromacs.org/current/reference-manual/special/pulling.html.