Unfortunately, this depends on the circumstances. If a coroner has requested a post-mortem, you can’t stop this from happening. All you can do is tell the coroner’s office how you would like your loved one to be treated. For example, if the person was a Muslim female, you could request that a female pathologist carries out the examination in line with your religious beliefs.
If a doctor asks you to carry out a post-mortem examination after your loved one died in the hospital, then the next of kin can refuse this. This may be due to religious or cultural beliefs. Or it may be a personal choice. Whether you give consent to a post-mortem in this case is completely up to you.