modifying the UploadEx.aspx or Upload.aspx isn't a good idea as You will by modifying an application page under /layouts/15 which is shared for all libs across the farm.
Maybe better approach would be to try to get all CT that are associated with this lib by PowerShell or CSOM and try to find the not valid ones and get their GUID. Then get all the items with this not valid CT and change it to a valid one. After that remove the not valid CT from list and change the default CT to some valid one.
Here is some simple powershell to get all CT in list (this would be a good script to start if You will consider this approach)
if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
Add-PSSnapin "Microsoft.SharePoint.PowerShell";
}
$_URL = "URL";
$SPWeb = Get-SPWeb $_URL;
$SPList = $SPWeb.Lists["LIST_NAME"];
foreach($ct in $SPList.ContentTypes)
{
$ct.Name;
$ct.Id;
}
let me know if this was of any help :)
***** UPDATE *****
Since You want to modify the upload application page and I suggested attaching some javascript to it I would go with Rest Api to get CT for list and also the ones attached to Document Set.
something like
https://{SITE_URL}/_api/web/Lists/getbytitle('{LIST_NAME}')/items?$select=Title,ContentTypeId
should do the trick.
so the request would look something like this
$.ajax({
url: "https://{SITE_URL}/_api/web/Lists/getbytitle('{LIST_NAME}')/items?$select=Title,ContentTypeId",
type: "GET",
cache: false,
headers: {
"accept": "application/json; odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: function(data) {
console.log(data.d.ContentTypes.results);
},
error: function() {
console.log("error");
}});
Please be aware that the above code with request is not tested... but I think should work or some small changes will be needed :)