Why was Amnon not punished by David for raping Tamar?
There are two reasons that David took no action against the offender.
1/ No formal charges of accusation made -Deuteronomy 19:15
2/ Absalom requested his sister to keep silent, he also did not speak to Amnon . 2 Samuel 13: 20,22
18 "Now she had on a [h]long-sleeved garment; for in this manner the virgin daughters of the king dressed themselves in robes. Then his attendant took her out and locked the door behind her. 19 Tamar put [i]ashes on her head and tore her [j]long-sleeved garment which was on her; and she put her hand on her head and went away, crying aloud as she went."
20 "Then Absalom her brother said to her, “Has Amnon your brother been with you? But now keep silent, my sister, he is your brother; do not take this matter to heart.” So Tamar remained and was desolate in her brother Absalom’s house.21 Now when King David heard of all these matters, he was very angry. 22 But Absalom did not speak to Amnon either good or bad; for Absalom hated Amnon because he had violated his sister Tamar."
David was very angry, but in view that no formal charges of accusation were made and in the absense of evidence, David could not take any action against the offender -(Read- Deut 19:15 below.)
Also you will note in verse 20 that AmnonAbsalom requested his sister to keep silent, perhaps to save him and his family unpleasant publicity.
Deuteronomy 19:15 (NASB)
15 “A single witness shall not rise up against a man on account of any iniquity or any sin [a]which he has committed; on the evidence of two or three witnesses a matter shall be confirmed."