Let $R$ be a prime ring of characteristic different from $2$, $U$ the Utumi quotient ring of $R$, $C=Z(U)$ the extended centroid of $R$, $L$ a non-central Lie ideal of $R$, $F$ a non-zero generalized derivation of $R$. Suppose that $[F(u),u]F(u)=0$ for all $u\in L$, then one of the following holds: (1) there exists $\alpha \in C$ such that $F(x)=\alpha x$ for all $x\in R$; (2) $R$ satisfies the standard identity $s_4$ and there exist $a\in U$ and $\alpha \in C$ such that $F(x)=ax+xa+\alpha x$ for all $x\in R$. We also extend the result to the one-sided case. Finally, as an application we obtain some range inclusion results of continuous or spectrally bounded generalized derivations on Banach algebras.