I think it's vast oversimplification to say a situation like this is always ok. Legally, you may be allowed to do such a thing currently but it's obvious there's a moral grey area here.
Hypothetically, say technology advances and not only do we have sophisticated AI but the technology to copy and store human intelligence. You do just that for a friend and that friend passes away. You now have the only extant copy of your friends intelligence and you notice that it's extremely similar in composition and cognition as an AI you also have on your drive. Is it ethical to delete either? I'd lean towards no.