Generally there are three choices for the kind of quantifiers addressed here. Although the OP's question uses numeral quantifiers, the same would be true for others, such as すべて, etc.
Attributive position
That is the case where the quantifier, marked by の, precedes the noun, e.g. the OP's third example.
Composition
Composition is when the quantifier follows the noun, but not the case marker. See the third to sixth of the OP's examples. OP claims that the fifth example is bad, but I don't think it is (as bad as is claimed).
Quantifier floating construction
Quantifier floating is when the quantifier follows not only the noun, but also the case marker.
(1) 3本のペンを買いました。
[[[quantifier-case]noun-case]...verb]
There the quantifier is subordinate to its host noun. From that position, the quantifier can float beyond its host noun. It then resides in a structurally higher position than in (1). The result is the OP's first sentence, i.e.
(2) ペンを3本買いました。
[[noun-case][quantifier]...verb]
Japanese quantifier floating has captured the attention of linguists because it helps identify a subject-object asymmetry. Compare the next two sentences:
(3) ペンを学生が3本買いました。
A student bought three pens.
(4) * 学生がペンを3人買いました。
Three students bought pens.
In (3), the quantifier floats, and produces (1). Then the object ペンを scrambles, i.e. moves across the subject 学生が. As a result, the subject now intervenes between the host noun and its quantifier.
Example (4) illustrates that the same is not possible with subject-related quantifiers. The conclusion many linguists draw is that in order for an object to be able to intervene between a subject and its floated quantifier, the subject must be base-generated in a position after the object, i.e. in OSV word order. (4) being ungrammatical, is thus seen as support that Japanese is "truly" a SOV language.
Quantifier floating in Japanese seems to be largely restricted to host nouns marked with nominative (が)or accusative (を)case. Other rare cases are discussed in Shigeru Miyagawa (1989: Structure and Case Marking in Japanese, Academic Press).
In Miyagawa & Saito (eds) The Oxford Handbook of Japanese linguistics link, there is a good section on floated quantifiers. An overview of quantifier floating in other languages can be found here.
Other quantifiers
Note that there are quantifiers that cannot appear in the constructions above. Attribution, composition, and floating are only available for quantifier adjuncts that scope over a noun. There are, however, also quantifier adjuncts and arguments over verbs:
(5) 亀は100年間生きることがある。
Turtles may live 100 years.
(6) 物価は3%上がった。
Prices rose by 3 percent.
Example (5) shows the quantifier adjunct/adverb 100年間, which scopes over the verb. (5) cannot be rephrased using attribution or composition. Since attribution is not available, floating is neither.
Example (6) shows the quantifier argument 3%. Again, attribution, composition, and/or floating are not available. Another interesting point is that quantifier arguments can express differential and absolute values. Quantifier adjuncts always express absolute values.