This question is a bit tricky, because there are two parts to the answer: how they got their powers, and why they specifically got powers that way.
What we know definitively is that said abilities manifested as a result of HYDRA experiments, and that they had no such abilities prior to HYDRA intervention.
Starting with the post-credits scene from Captain America: The Winter Soldier, plus the opening act of Age of Ultron, we're told that HYDRA (specifically, Baron Strucker and Dr. List) have been experimenting on humans by using the power from Loki's scepter. During Age of Ultron, we eventually learn that this power is, in fact,
one of the Infinity Stones -- the Mind Stone.
The twins are not the only people who were experimented on by HYDRA, they were merely the only two who survived. At the end of The Winter Soldier we see them in cells, with Wanda making things levitate and Peitro zipping around the cell at high speed. Based on Dr. List's comments, HYDRA's goal was to try to create an army of enhanced soldiers to take on the Avengers. Unfortunately, all of the others except the Maximoff twins died in the process. Ultron even calls this out, when he says something like "I used to wonder why you two were the only ones to survive Strucker's experiments."
However, on the question of the ultimate origin of those powers, that's a bit less clear. There is some evidence -- inconclusive but compelling -- that the twins had latent powers, and that may be why they survived the experiments. The comic prelude to Age of Ultron includes some dialog between the twins and List, describing the experiments:
Note that he uses the term "unlock" to describe the process of enhancing the twins with powers. Whether he was literally talking about bringing out latent abilities (e.g. they are something like Inhumans), or was just being metaphorical (in the sense of "unlocking" some new age of science) isn't clear. We know from Agents of SHIELD that people within HYDRA (e.g. Dr. Whitehall) were aware of the Inhumans and the abilities they possessed, and were trying to replicate them.
Whether the twins are Inhumans, are some other form of naturally-enhanced metahuman, or are normal humans who's powers were created from scratch by the scepter is still a somewhat open question.