As far as I know, all of the major consumer DNA testing companies (AncestryDNA, 23andMe, FamilyTreeDNA, MyHeritage, LivingDNA) and websites that have DNA matching (GEDmatch, Geni.com, DNA.land, etc.) require that you confirm the DNA sample or raw data being submitted is your own, or that of someone for whom you are a legal guardian or have obtained consent. Also, I believe the two companies with the largest DNA databases, AncestryDNA and 23andMe, accept only saliva samples for testing, and do not accept raw data uploads.
http://www.genie1.com.au/blog/58-which-dna-testing-company
Apparently police in the U.S.A., as in the recent case in California, may be able to upload the autosomal DNA data of an unknown suspect, obtained after analyzing samples at crime scenes, to these websites that accept raw data uploads, despite obviously not having that person's authorization, since "DNA abandoned by the perpetrator of a crime basically has no legal protection", according to a professor of law quoted in this article.
Investigators searched a million people’s DNA to find Golden State serial killer
This would be done in hope of obtaining the name of a cousin or other relative of the suspect, and eventually identifying the suspect through further investigation. As the police investigators are using these websites like any other person, and the only information being obtained by them would be the name of someone voluntarily displaying it (and not their actual DNA data -- the A-C-G-T's), they do not need a court order.
From the first post of this thread, it would appear that any exhumation of an unidentified Titanic victim would occur only after someone had presented compelling evidence to local authorities that it was one of their relatives. If DNA was obtained from the exhumation, and it did not match the person thought to be related, it would certainly present an interesting situation. I have no idea if the authorities in Halifax would then be legally allowed to submit the DNA data to those DNA testing companies in an attempt to find someone related. The total database of all those companies was estimated to be 12 million earlier this year, with AncesrtyDNA alone at over 7 million and likely to exceed 10 million in 2018. And most of the people using them have been from largely English speaking countries (U.S.A., Canada, Britain, Ireland, Australia, and New Zealand), so I would guess there would be a very high probability of finding a relative, even if it was only a distant cousin, for most of the unidentified victims.
Perhaps before considering any such wide search of that kind if the situation did arise, a more reasonable course of action would be attempting to determine other possible identities for the victim, followed by efforts to locate their relatives.