A popular theory you may see going around is that during her mental duel with Kylo Ren,
she learnt how to use the Force after accidentally breaking into Kylo Ren's mind out of sheer desperation to resist him. That short moment spent in his mind was apparently all she needed to glean all the knowledge she needs to use the Force.
However, unless someone can back it up with actual proof from the novelisations, I would disagree with this theory for the sole reason that her foundation is different from his - whenever she is consciously using the Force as opposed to knee-jerk reactions, she is visibly calm and internally at peace, in the same way as the Jedi of old and not at all like one who would be using the dark side instead.
Examples include her attempt at a mind trick, and the second half of her lightsaber duel with Kylo Ren.
Now that we get that out of the way, I would point out a few facts:
- While in Maz Kanata's castle, her first conscious contact with the Force occurred. She wasn't willing nor able to understand and accept what just happened, but by the time she was done with her mental duel with Kylo Ren, she had spent some time in isolated captivity processing everything and came to the conclusion that she is Force-sensitive.
- Since young, she has heard "stories about what happened". Rumours about the Jedi, the Force and the dark side...and surely what they are capable of.
- She also grew up a scavenger. The mentality such a life develops equips her with the skillset to be more inclined towards creativity, improvisation, and taking things apart to understand how they work.
Putting two and two together, I would suggest that, having accepted her Force sensitivity, she started to walk back through her memories and figure out how she did what she did. Then, having heard stories of what the Jedi of old were capable of, she decided to see if she can do one of them - a mind trick to get a stormtrooper to release her.
It failed the first time, but I guess it helps that Maz Kanata had told her a little bit about the Force, enough to set her on the right path, to compose her mind and emotions. And voila, the second attempt works.
Admittedly, a mind trick is rather advanced - even Ahsoka Tano took time as a Padawan to improve her proficiency until it works unfailingly. However, bear in mind that Luke Skywalker was able to vastly improve his mastery of the Force in the six months between Bespin, when he lost his hand to Vader, to Endor, when Vader lost his hand to him.
We don't have an exact timeframe between Rey's capture to Kylo's interrogation to her escape - it could be days or weeks. However, the fact that she can grow leaps and bounds in her innate ability to use the Force should not be seen as something unbelievable and one of the so-called reasons J.J. Abrams ruined TFA - to do so would be to unwisely set a constraint on what is possible with the Force. Rather, it should speak volumes about just how naturally strong Rey is in the Force.