The main objective of Gintama is truly to become a parody of the different anime series that are considered to be popular. If it makes a parody of a certain series, this is a sure sign that the series is popular. A lot of the series that Gintama parodies come from the same company.
This means that there is no need to worry about copyright anymore. There are also other anime series that Gintama parodies that it does not parody by name. This means that they do not use the name of the series so they cannot be copyrighted for it. It helps that they are very careful about the material that they produce. They are entertaining without causing problems for others.
Gintama is popular for parodies of different anime. So with copyright infringement being so strict, many people ask how Gintama does not get shut down for copying these different animes. The answer is that for many of them, they come from the same studio as Gintama so the studio holds the rights to several anime and therefore can parody or mention it as many times as they want.
Other animes like dragon ball z and naruto are not specifically mentioned by name so there is no copyright infringement involved with animes where they change the name slightly or only hint at the similarities.