I've never written a trainer myself, but I would guess that they operate by editing specific locations in the game's memory. Access to the game's address space can be gained by DLL injection or by using a debugger-style API like
To alter specific aspects of the running game (health, points, resources etc.) you have to figure out exactly where in the game's memory this data is stored. In practice, the location of this data probably varies from one session to the next (due to nondeterministic heap allocations, etc.), so really you have to figure out how to find that data starting from a reliable address (such as a global variable in the data section of the game's .exe) and following pointers, etc. This is the hard part.
Once you know where the data is, you just overwrite it with your desired value.