Who wrote the laws of the Tanakh and who commanded his disciples to buy swords?
Peter didn't live by the sword dude but those that came to arrest Jesus did. Furthermore Jesus didn't want his disciples to resist his arrest.
Why did He command His disciples to buy swords?
NKJV quotes it correctly
Matthew 26:52
New King James Version (NKJV)
52 But Jesus said to him, “Put your sword in its place, for all who take the sword will perish[a] by the sword.
It's not live...it's "take" - literal translation
λαμβάνω,v \{lam-ban'-o}
1) to take 1a) to take with the hand, lay hold of, any person or thing in order to use it 1a1) to take up a thing to be carried 1a2) to take upon one's self 1b) to take in order to carry away 1b1) without the notion of violence, i,e to remove, take away 1c) to take what is one's own, to take to one's self, to make one's own 1c1) to claim, procure, for one's self 1c1a) to associate with one's self as companion, attendant 1c2) of that which when taken is not let go, to seize, to lay hold of, apprehend 1c3) to take by craft (our catch, used of hunters, fisherman, etc.), to circumvent one by fraud 1c4) to take to one's self, lay hold upon, take possession of, i.e. to appropriate to one's self 1c5) catch at, reach after, strive to obtain 1c6) to take a thing due, to collect, gather (tribute) 1d) to take 1d1) to admit, receive 1d2) to receive what is offered 1d3) not to refuse or reject 1d4) to receive a person, give him access to one's self, 1d41) to regard any one's power, rank, external circumstances, and on that account to do some injustice or neglect something 1e) to take, to choose, select 1f) to take beginning, to prove anything, to make a trial of, to experience 2) to receive (what is given), to gain, get, obtain, to get back For Synonyms see entry 5877
τότε λέγει αὐτῷ ὁ Ἰησοῦς, Ἀπόστρεψον τὴν μάχαιράν σου εἰς τὸν τόπον αὐτῆς, πάντες γὰρ οἱ λαβόντες μάχαιραν ἐν μαχαίρῃ ἀπολοῦνται.