Why would a CI/CD need to permissions modify and commit code to a repo?
So if an attacker compromises the API key used by that pipeline, they get the rights to push to Rubygems.
It'd depend on the individual software library and of course as a consumer of many libraries you generally will have limited or no visibility of the practices of all your dependencies.
As a consumer of software libraries, have you ever looked into the security practices of the library author before choosing whether to use it or not?