If he was really here for Shangguan Yan, then his motive was not difficult to guess. He had most likely blamed Nangong Yan on Prince Yan. He probably thought that everything Prince Yan did now was for Shangguan Yan, so he wanted to kill Shangguan Yan to vent his anger.
Instead of saying that he was avenging Nangong Yan, it was more like he was venting his jealousy.
Yu Wan said, "I'm afraid he still doesn't know that he's not Father's flesh and blood. He's still holding a grudge that you've been the only one Father remembers over and over again all these years."
No matter how many times he was fed Soul Devouring Grass, Prince Yan could remember Yan Jiuchao's name, but Nangong Li had never been remembered by Prince Yan.
He could not defeat Yan Jiuchao, so he targeted the ignorant and helpless Shangguan Yan. This was really a sign of cowardice and incompetence.