What should a chess beginner do with his/her knights after 2. Nf3 or 2. Nc3? Let us suppose I am a chess beginner. I often lose my games. Well, it depends on the opponent but generally I can hardly win. My problem is I do not know what I should do with my knights.

Usually chess textbooks or people whom I asked for advice tell me, "You must develop your knights very early in the game; it's necessary for castling." After that, they don't give any more useful information.

I simply do not know what to do after I castled... For example, I've played 1. e4 2. Nf3 3. Bc4 4. 0-0. After that, I am stuck. A few times, I tried to be brave and to advance my knight forward in hope of giving a smothered checkmate, but I always had to encounter the opponent's queen, which is extremely powerful. Returning my knight to initial square doesn't make any sense for me. And not making any further moves with my knight seems to be pretty stupid as well.
The knights don't necessarily move beyond the third rank in the opening. The middlegame is more variable and depends on the opening, but I think the main "rule" you need to remember is that knights, being slow pieces, work best when they are supported. You generally should avoid advancing a knight unprotected, where it could be lost to a tactic. The best support for a knight is a pawn, but also you don't want your knight to be "kicked back" by an enemy pawn (unless that move would be bad for your opponent for some other reason), so the ideal square for a knight is an outpost, which quoting the Wikipedia definition is "a square on the fourth, fifth, sixth, or seventh rank which is protected by a pawn and which cannot be attacked by an opponent's pawn."

One more thing to consider is that, if you castle short, the f3 knight also has an important defensive role since it defends the h2 pawn, which is often a target of attack. That doesn't mean you can never move the knight, but you should be wary when there are enemy pieces threatening that pawn. A famous attacking pattern known as the "Greek gift" begins by sacrificing a bishop for the h2 pawn (or h7 against Black, of course!).