How to understand the hadeeth when the prophet instructed the one who prayed badly to repeat his prayer and not ordering Mu’awiyah to repeat it?
Question

                How can I understand and join between the hadeeth of when Mu’awiyah said to a person who sneezed “May Allah have mercy on you” while he was praying, and the Prophet, peace be upon him, did not order him to repeat his prayer. Mu’awiyah did not know that external talk during the prayer invalidates it. For the Prophet, Peace be upon him, not to order Mu’awiyah to repeat his prayer, this means that his prayer is valid. And the other hadeeth of when the prophet, peace be upon him, ordered the one who prayed badly to repeat his prayer. This means his prayers was invalid even though he was ignorant of how to pray properly?.
Praise be to Allah.The hadeeth of Mu’aawiyah 
    ibn al-Hakam was narrated by Muslim (537) from Mu’aawiyah ibn al-Hakam who 
    said: Whilst I was praying with the Messenger of Allaah  (peace and 
    blessings of Allaah be upon him), a man among the people sneezed and I said:
    Yarhamuk Allaah (may Allah have mercy on you). The people 
    glared at me and I said: May my mother be bereft of me! Why are you staring 
    at me? They started striking their hands on their thighs, and when I 
    realized that they were telling me to be quiet, (I felt angry) but I kept 
    quiet. When the Messenger of Allaah  (peace and blessings of Allaah be 
    upon him) had prayed – may my father and mother be sacrificed for him; by 
    Allaah I have never seen a better teacher or better teachings before or 
    since; he did not rebuke me, hit me or revile me – he said: “This prayer is 
    not the right place for any of the people’s speech, rather it is tasbeeh, 
    takbeer and recitation of Qur’aan.” 
The hadeeth about the man 
    who prayed badly was narrated by al-Bukhaari (757) and Muslim (397) from Abu 
    Hurayrah (may Allaah be pleased with him), that the Messenger of Allaah  
    (peace and blessings of Allaah be upon him) entered the mosque and a man 
    came in and prayed, then he came and greeted the Messenger of Allaah  
    (peace and blessings of Allaah be upon him). The Messenger of Allaah  
    (peace and blessings of Allaah be upon him) returned the greeting and said: 
    “Go back and pray, for you have not prayed.” The man went back and prayed as 
    he had prayed before, then he came to the Prophet  (peace and blessings 
    of Allaah be upon him) and greeted him, and the Messenger of Allaah  
    (peace and blessings of Allaah be upon him) said, “Wa ‘alayk al-salaam.” 
    Then he said: “Go back and pray, for you have not prayed.” When he had done 
    that three times, the man said: By the One Who sent you with the truth, I 
    cannot do more than that. Teach me. He said: “When you go to pray, say 
    takbeer, then recite whatever you can of the Qur’aan. Then bow until you are 
    at ease in bowing, then rise until you are standing up straight. Then 
    prostrate until you are at ease in prostration, then sit up until you are at 
    ease in sitting. Then do that throughout the entire prayer.” 
Both ahaadeeth indicate 
    that the one who is ignorant is excused, but in the hadeeth of Mu’aawiyah he 
    is not commanded to repeat the prayer, whereas in the hadeeth of the one who 
    prayed badly, he is not commanded to repeat the prayers he had offered 
    before, rather he was commanded to repeat the current prayer only. 
Al-Nawawi (may Allaah have 
    mercy on him) said, commenting on the hadeeth of Mu’aawiyah: As for the 
    words of the ignorant one, it was because he was new in Islam, so they are 
    like the words of one who forgets, so they did not invalidate his prayer if 
    they were few, because of this hadeeth of Mu’aawiyah ibn al-Hakam, which we 
    are discussing here, because the Prophet  (peace and blessings of Allaah 
    be upon him) did not command him to repeat the prayer. But he taught him 
    that it is haraam to talk during prayers for future reference. End quote. 
With regard to commanding 
    the one who prayed badly to repeat his prayer when he did not command 
    Mu’aawiyah to do so, that is because there is a difference between doing 
    that which is forbidden and not doing that which is enjoined. Omitting what 
    is enjoined is not excused because of ignorance or forgetfulness when it is 
    possible to make it up, which is unlike doing what is forbidden. 
Shaykh Ibn ‘Uthaymeen (may 
    Allaah have mercy on him) said, in a discussion of things that are forbidden 
    whilst in ihraam: The correct view is that all of them may be excused. If a 
    person is excused due to ignorance, forgetting or being forced to do 
    something , there are no consequences to his actions whatsoever, whether it 
    has to do with having intercourse, hunting, clipping the nails, wearing 
    tailored garments or anything else. We have mentioned above evidence from 
    the Qur’aan, Sunnah and rational thought.  
The same applies to all 
    other actions that are forbidden during acts of worship; the ruling does not 
    apply, if they happen in cases of ignorance forgetfulness or compulsion, 
    because of the general meaning of the texts and because the penalty, fidyah 
    or kafaarah (expiation) is only prescribed in order to compensate for going 
    against the rules or to expiate sins, but the ignorant, forgetful person or 
    one who is forced did not deliberately go against the rules, and if he had 
    remembered, been aware or had the choice he would not have done it. 
If a person drinks by 
    mistake in Ramadaan (because he forgets he is fasting), he does not have to 
    make it up. The evidence for that is the hadeeth of Abu Hurayrah (may Allaah 
    be pleased with him): “Whoever forgets when he is fasting and eats or 
    drinks, let him complete his fast, for it is Allaah Who has fed him and 
    given him to drink.” The one who does not deliberately go against the rule 
    is not sinning and does not have to offer any fidyah. 
Similarly, when ‘Adiyy ibn 
    Haatim wanted to fast, he took a black thread and a white thread, because of 
    the verse in which Allaah says (interpretation of the meaning): “and eat 
    and drink until the white thread (light) of dawn appears to you distinct 
    from the black thread (darkness of night), then complete your Sawm (fast) 
    till the nightfall” [al-Baqarah 2:187]. They used to take the rulings 
    directly from the Qur'aan. But the Prophet  (peace and blessings of 
    Allaah be upon him) said to him: “Your pillow must be very wide, if the 
    black and white threads are beneath your pillow.” But he did not command him 
    to repeat the fast because he was ignorant of the ruling. 
Similarly, Asma’ bint Abi 
    Bakr (may Allaah be pleased with her) said that they broke the fast on a 
    cloudy day at the time of the Messenger of Allaah  (peace and blessings 
    of Allaah be upon him), and he did not command them to make it up – because 
    they were unaware of the fact that the sun had not yet set. 
The same applies to prayer. 
    The evidence is that Mu’aawiyah ibn al-Hakam (may Allaah be pleased with 
    him) started to pray with the Prophet  (peace and blessings of Allaah be 
    upon him) and a man sneezed, so he said, “Yarhamuk-Allaah (may Allaah 
    have mercy on you)” whilst he was praying. The people glared at him – i.e., 
    they looked at him disapprovingly – and he (may Allaah be pleased with him) 
    said, “May my mother be bereft of me!”, i.e., he added more words to what he 
    had said. So they started to slap their thighs with their hands to make him 
    be quiet, and he fell silent. When he had said the salaam, the Messenger 
     (peace and blessings of Allaah be upon him) called him. Mu’aawiyah 
    said: May my father and mother be sacrificed for him; by Allaah I have never 
    seen a better teacher or better teachings before or since; he did not rebuke 
    me, hit me or revile me – he said: “This prayer is not the right place for 
    any of the people’s speech, rather it is tasbeeh, takbeer and recitation of 
    Qur’aan.” And he did not tell him to repeat it because he was unaware of the 
    ruling. 
The texts point to this 
    principle, which is not blaming people for forgetting, not knowing, or being 
    forced to do something. This is what is implied by the words of Allaah 
    (interpretation of the meaning):
“your Lord has written 
    (prescribed) Mercy for Himself, so that if any of you does evil in 
    ignorance, and thereafter repents and does righteous good deeds (by obeying 
    Allaah), then surely, He is Oft‑Forgiving, Most Merciful”
[al-An’aam 6:54], 
And the words of Allaah in 
    the hadeeth qudsi: “My mercy prevails over My wrath.” 
Omitting to do that which 
    is enjoined, however, is not excused on the basis of forgetting, ignorance 
    or being forced, when it is possible to make it up, because the Prophet  
    (peace and blessings of Allaah be upon him) said: “Whoever sleeps and misses 
    a prayer or forgets it, let him pray it when he remembers it.” So it is not 
    waved in the case of forgetting. And because the Prophet  (peace and 
    blessings of Allaah be upon him) did not waive the current prayer on the 
    grounds of ignorance, as we see in the hadeeth of the one who prayed badly; 
    he commanded him to repeat it even though he was ignorant, because he was 
    omitting to do something enjoined.  
Moreover, it is possible to 
    make up things that are enjoined, but forbidden things are over and done 
    with. But if a person is doing something that is forbidden, he should stop 
    doing it as soon as he realizes. If someone says that Allaah’s words 
    (interpretation of the meaning): “Our Lord! Punish us not if we forget or 
    fall into error” [al-Baqarah 2:286] are general in meaning and include 
    both omitting things that are enjoined and doing things that are forbidden, 
    the response is that that is indeed the case; the one who does not do 
    something that is enjoined out of ignorance or because he forgets will not 
    be punished for not doing it, but not doing it means that he is obliged to 
    discharge his duty once the excuse is no longer applicable. End quote from
    al-Sharh al-Mumti’ (7/200). 
And Allaah knows best.