Sed not the best tool for this task. It does not look forward, it does not look greedy quantifiers, but try the following command:
sed -r -e ':a ; s/\b([a-zA-Z]+)\b(.*) (\1)( |$)/\1\2 *\3* / ; ta'
It uses conditional branching to execute the substitution command until it works. Also, you cannot check ([^*]+) because for the second round it must cross part * first substitution, your option is greedy .* . And last, you cannot match (\1) just because it will match the first line of lol again and again. You need some kind of context surrounded by spaces or the end of a line.
The command gives:
lol foo *lol* bar *foo* *bar*
UPDATE : improvement provided by potong in the comments:
sed -r ':a;s/\b(([[:alpha:]]+)\s.*\s)\2\b/\1*\2*/;ta' file
Birei source share