This fashion reached its peak of size and decoration in the 1540s before falling out of use by the 1590s.
https://en.wikipedia.org/wiki/Codpiece
It seems that codpieces quickly became popular in the 16th century Europe and then fell out of fashion. Was there any particular reason for this rise and fall? Moral objection? Or just a simple trend?
This is somewhat difficult to answer I must admit, but bare with me. I think it's important to understand and consider the topic before we go straight to claims and answers, especially where uncertainty is most prominent. The context is more revealing here than any attempted explanation.
Thomas Luttenberg ("The Cod-pieceāA Renaissance Fashion between Sign and Artefact", 2005) defines the codpiece as an example of contradictory culture, in relevance to this odd juxtaposition of an item both popular and not-uncommonly seen as salacious. It is a "sign and artefact" of the culture of shame. His hypothesis is that its meaning was significantly to do with male virility and the penis, but also similar and related meanings around male power and even male reason (which seems strange to us). It might be better to understand them as symbols of maleness rather than purely sexual or purely not. The sexual connotation exists so far as they represent that maleness through a bodily symbol. But not because they were always thought of it in lewd terms. Jeffrey C. Percels in "Bragueta Humanistica, or Humanism's Codpiece" (1997) also talks about this multi-faceted and not purely sexual meaning of masculinity in the codpiece.
Luttenberg mentions criticism of the cod-piece, both in the early era of the late 15th century when it first started to grow in size, and in the sixteenth century when large cod-pieces became normalised for a time. These criticisms feature both the element more obvious to us of the sexual implications and the less obvious, but more important for the time, aspect of naturalness.
It really is important to understand the culture of the time around naturalness of exteriors. With cost of clothing, use of makeup, disabilities (particularly aesthetic "deformities) and with specific clothes like cod-pieces, among other things, there was the idea that things should look like what they are "supposed" to look like, based on what was perceived as natural for that thing. So elites were allowed to wear showy, sumptuous clothing that embellished their look, but to many, makeup (primarily female at this time) was suspicious as as a way of not just putting on garnish but covering up the real look of your skin in areas that should, supposedly, be left natural aside from hygiene. Skincare washes were less suspicious, but "paintings" like the famous white powder look associated with Queen Elizabeth I, oddly it's difficult to determine if she actually wore such stuffs, were definitely criticised, despite growing popularity. In Hamlet, when he says "I have heard of your painting too, well enough, God has given you one face and you make yourselves another",, he is referring to this stronger class of makeups like venetian ceruse and vermilion which, aside from being less subtle than a facewash, were also poisonous. We can't ignore the obvious influence of misogyny here, that makeup mostly associated with women at this time is treated as something for deceivers and whores. I suspect we would find less of this condemnation later in the 18th century when men adopted these "paintings".
In a similar vein, a lot of the criticism of codpieces that Luttenberg identifies actually makes more of the unnaturalness of having a protruding or padded-thick codpiece, because they see it as a form of deception or distorting of the natural body. The moral value equated with this is significant, as one 1555 critic invokes both the sin of superbia (pride) and the eighth commandment (thou shalt not bear false witness) and describes both excessive codpieces and excessively large pumpkin breeches as unnatural shapes. The padding of breeches was actually more commonly a target of criticism from moralistic preachers according to Luttenberg.
To focus on the decline, Historian Victoria Bartels suggests that the codpieces decline may be more to do with the role of the peascod belly as an alternative; https://www.cam.ac.uk/research/features/what-goes-up-must-come-down-a-brief-history-of-the-codpiece. And the article also notes that around this time fashion was emphasising the face and hips with ruffs, wired collar and breeches which is often considered one reason why. So it may have been more a change in fashion than any particular moralism, although it's noteworthy the peascod belly was relatively briefly in fashion and the codpiece did not suddenly get bigger again when doublets slimmed in the 1590s. Aside from the odd example like this portrait https://en.wikipedia.org/wiki/Charles_Howard,_1st_Earl_of_Nottingham#/media/File:Daniel_Mytens_(c.1590-1647)_-_Charles_Howard_(1536%E2%80%931624),_1st_Earl_of_Nottingham_-_BHC2786_-_Royal_Museums_Greenwich.jpg (notably of an older military man who is wearing conservative skirts instead of breeches) codpieces in the late 16th century and early 17th century stayed relatively small. So I don't think the peascod alone explains it, especially as the final decline of large codpieces, and codpieces altogether, was the introduction of mid-17th-century breeches that would eventually evolve into 19th century trousers.
So, in conclusion, it's difficult to explain the relatively brief and rapid rise and fall of large codpieces. Masculinity ideas and the competitive elements of culture in the Long Sixteenth Century culture (include a number of monarchs growing in power like Henry VIII who wanted to show off) certainly contributed to its initial rise. But moralistic concern itself doesn't seem to have sunk it, in so far as it persisted while criticism occurred and was not usually the focus. Fashion changes generally seem to have been a major factor, perhaps alongside a degree of moralism.