Data downloaded his memory when he realized he was going to die, with the intention that it was to be uploaded to his brother, B4. This would not have conflicted with DATA's ethical subroutines because in his last interaction with B4, DATA tells him that he is to remain deactivated indefinitely, essentially making him a spare body. DATA must have left behind instructions for his memory integration and his reasoning for B4's indefinite deactivation. You could argue (since, in the end of Nemesis, we see a reactivated B4 conversing with Picard) that Starfleet would have objected on ethical grounds, but B4's sentience could easily be argued, as his response to most any input was, "I do not understand". DATA nearly failed to establish himself as a life form in "The Measure of a Man". B4 would have absolutely failed had such a hearing taken place for him. Even if he would have succeeded, when faced with the reality of a Starfleet without DATA, they would have denied B4 and still went through with the procedure.
The real question, as far as DATA is concerned; given that we weren't anywhere close to the first beings to develop WARP capability, how the hell is DATA the only one of his kind? Shouldn't there be android Vulcans, Romulans, Klingons, Bajorans, Cardassians, etc. You'd think at the very least, the Ferengi would have a civilization of androids, since you wouldn't have to pay them for their work.