One motivation could be Snape's sense of duty as a teacher. Despite his dislike for Harry in some ways, he still has an obligation to protect the students. So, when he sees Lockhart endangering Harry, he steps in.
Another possibility is that Snape uses his position as a teacher. He might threaten Lockhart with the consequences of harming a student. Given Snape's intimidating presence and his own power within the school, Lockhart would be afraid to cross him. Snape could also call for other teachers to help, making it clear that he won't let Lockhart get away with any harm to Harry.
The Dursleys might be left in a state of shock and confusion. Since they have been so mean to Harry, they could be worried that the wizarding world will come after them for revenge. But since they are Muggles, the wizarding world may just leave them be, but they will always live in fear of the unknown.
One possible plotline could be that Lockhart attempts to use Harry for some self - promoting stunt that goes horribly wrong, and Severus steps in to rescue Harry from the immediate danger. For example, Lockhart might try to make Harry participate in a dangerous magic display for his own glory, but Severus, seeing the real danger, intervenes.
In fanfiction, Snape saving Harry often showcases a complex side of Snape's character. It might be a redemption arc for him, as in the original series, Snape had a very ambiguous relationship with Harry. In these fanfictions, it could be due to his love for Lily that he finally decides to fully protect Harry, which is a very interesting take on his character.
One popular 'Severus saves Harry from Lockhart' fanfic might be found on platforms like Archive of Our Own. You can search using those exact keywords in the search bar on the site to find relevant stories.
Perhaps Snape uses magic to create a distraction at the Dursleys' place. He could make strange noises or apparitions that scare the Dursleys, and while they are in a panic, he grabs Harry and disapparates. This would be a quick and efficient way for him to rescue Harry.
In this type of fanfiction, Snape could simply intimidate Vernon. Snape has an air of mystery and a certain power about him. He might show up at Vernon's doorstep, give Vernon a cold stare, and with his reputation as a powerful wizard, Vernon might be too scared to oppose him. Snape could then just take Harry without much resistance from Vernon.
They might face magical justice. In some fanfictions, the Ministry of Magic could get involved and strip them of their magic, or at least put them under strict surveillance.
Another theme is the clash of personalities. Lockhart is flamboyant and self - centered while Snape is brooding and often secretive. Fanfics often play on this contrast, creating interesting situations and dialogues between them.