Once an article obtains a badge, they cannot lose it unless the page gets deleted (archived pages still keep badges.)
For retroactively assigning badges, it doesn't matter how long an article was eligible for a badge. As long as it was eligible for a badge at some point, and this can be proven, the article gets the badge.
The contest winner and runner-up badges are pretty self explanatory. You don't need to meet any requirements other than your article having won first / second place in a contest. Note that winning by default still counts for a badge. Also, these badges should not be put on the archived contest entries, only on the final posted article. The challenge winner badge is similar, except for the monthly challenge.
Next up is the Top Joke badge. This badge only applies to -J RPCs (comedy tales don't count.) An article must have 25 votes or more in order to get this badge. Any -J that is higher than any other -J in either highest-rated-of-all-time or most-popular-of-all-time should get this badge.
Next is the Top Article badge. This badge can apply to any RPC or Tale. An article must have 25 votes or more to get this badge. If an RPC is the highest rated of all time, it gets this badge. A Tale can only get the badge for being highest rated of all time in the Tales section. A Tale cannot get this badge for the Most Popular section.
Finally is the Top Ten badge. Similarly to the Top Article badge, it can apply to any RPC or Tale. An article must have 25 votes or more to get this badge, while a tale must have 20. If an RPC is within the 10 highest rated of all time, they get this badge. If a tale is within the 10 highest rated Tales of all time, they get this badge. Tales cannot get this badge for the Most Popular section.
Note that the Top Article badge overrides the Top Ten badge. An article can't have both.
Articles cannot earn badges for appearing in the "Other Articles" sections of the Top Rated page.
The 10 highest rated articles of Legacy Top Rated are eligible for the Top Ten badge, and the highest rated is eligible for the Top Article badge. (With the exception of RPC-7143-J.)
Note that only staff / dev team are allowed to add badges to articles.
Make sure to use the proper tags when you add a badge to an article. Check the tagging guide for that.