BT has bought troubled broadband provider TalkTalk out of administration as fears that its collapse could raise national security concerns.