'Buy' is the base form of a verb (also called the bare infinitive), it should be modified when it is used in a sentence (bought, buying, to buy). From the options, 'to' is a preposition which when added to any base verb forms an infinitive. (An infinitive is a verb form: to + verb that refers to an action). 'To buy' refers to a purpose of buying. Hence option D is correct.
'For', 'from' and 'into' do not form infinitives with the bare verb 'buy'. Also, these prepositions are followed by nouns and not verbs (buy). Hence options A, B and C are incorrect.