"Who was elected president?" - obvious
"Who was elected by the president?" - Who was elected to some unnamed office by the president. It was the president who elected the person.
"Who was elected the president?" I am not sure. I am not strong enough in this topic and not an author of this exercise. I found this https://forum.wordreference.com/threads/bush-was-elected-the-president-of-the-united-states.2620380/ . But that is a specific example and our sentence is more general. If you have some credible source for allowing it, please show it.