Your question is a good one – and one I’ve never seen posted here or anywhere else before!
Yes, a religious can be made a bishop or a cardinal. The Archbishop of Boston, Sean O’Malley is both a Franciscan and a Cardinal (and, interestingly, one of his auxiliary bishops, Bishop Allue, is also a religious). They remain technically under their superior in the order but generally function as “detached” from the order because their primary service is to the diocese and not to the order.
Exceptions are also present such as Cardinal Avery Dulles who continues to be under his Jesuit superior. He does not run a diocese (nor, in fact, is he a bishop since he requested that he not be elevated to the episcopacy).
BTW, a religious ordained pope is not under a religious superior since the pope is not “under” anyone. They may maintain their connection with the order. In fact, the reason popes wear white is that a Dominican was made pope and continued to wear his Dominican habit. The white has stuck ever since…
Hope this helps.
Deacon Ed