When we make passive voice of 'I gave him an apple.', should we use preposition 'to' like 'an apple was given to him by me.' If we should, why?
You should use to. The other version isn't wrong, though.
There are two ways to say the basic sentence:
I gave an apple to him.
I gave him an apple.
And as a result, there are two passive sentences, too:
An apple was given to him (by me).
An apple was given him (by me).
The name for this pattern is the Dative Alternation, and you can read more about it in this answer.
Even though both of these sentences are grammatical, the version with to is much more common, especially in spontaneous speech. Why? Well, in the answer I linked above, I talked briefly about Rohdenburg's Complexity Principle, "explicitly marked phrases are preferred over zero-marked counterparts in cognitively complex environments". That answer was about questions, but it applies to passives, too.
Put more simply, we use to there because it helps us understand what role him plays in the sentence.
In fact, some speakers have such a strong preference for to here that they believe the other version is ungrammatical! But don't believe them; it's too well attested in Standard English writing for us to call it anything but grammatical. Here are some examples from the Corpus of Contemporary American English:
He struggled to kindle a spark of rebellion, to resist this fate, but fatigue and whatever narcotic had been given him for the pain muffled his fire. He just wanted to sleep.
Howard hands Curtin a gold nugget that has been given him by his Indian hosts and tells him to drop it into the village well.
When he finished dressing he washed his face and hands in the bowl and dried himself with the towel that had been given him at his bath a few days before. He took his toothbrush from his vest pocket and lathered some soap on it.
There were also two stuffed bears, which she'd named Alphonse and Gaston, and a frayed quilt, which had been given her when she was born.
All of these examples sound formal or bookish. In spontaneous speech, you're unlikely to hear this sort of example.
My recommendation? You should you get in the habit of using the to version, but make sure you can understand the version without to.
Even though there is the word "past" in "past participle", it's by itself un-tensed. And hence it needs an auxiliary verb to express "tense", so that a complete standalone sentence forms.
We can't say -
The apple given
Because it's not a standalone sentence. Of course it can be taken as a fragment of another sentence. To make it a standalone sentence we need to provide "tense". And therefore we need an auxiliary verb.
The apple was given.
Now this is a standalone complete sentence. This is a passive form. Now we need to provide two important information - one, who gave the apple and two, who received it. Both can be done using two Preposition Phrase (PP). The information - who gave the apple - can be achieved by the PP - by me. The information - who received the information - can be achieved by another PP - to him. So it becomes -
The apple was given to him by me.
Now the active form is
I gave the apple to him.
The preposition to is obligatory. Consider also the following sentences -
I gave him the apple.
He was given the apple by me.
Here to is not needed. And using it is wrong.
Let's start by looking at the first sentence
I gave him an apple
Strictly speaking, the sentence should be
I gave an apple to him
The subject is I, the object is apple and him is an indirect object linked by a preposition. It is normal, with to to swap the order of the direct and indirect objects and to drop the preposition. Thus:
I wrote a letter to him
I wrote him a letter
So, when we switch to passive voice, we are not adding a preposition: we are choosing not to omit it, because the sentence structure is more complex. It is still acceptable to say
An apple was given him by me
But it is less common.
I gave him an apple.
I gave an apple to him.
He was given an apple by me.
An apple was given to him by me.
An apple was given him by me.
When can usually say either "give him|her|me|them something" or "give something to him|her|me|them".
Although the passive forms above are grammatical, they are very unlikely to pass the lips of a native speaker. In normal conversation, most native speakers do not go out of their way to use the passive, as student textbooks might lead you to believe we do.
If an exercise textbook were to be written by me, many exercises would be presented in which passive constructions must be rephrased by the student as active constructions.
If I were to write an exercise textbook, it would present many exercises in which the student must rephrase passive constructions as active constructions.