Colouring SDL textures might be a little tricky. The following code should outline the main points of colouring a texture. The key is to fetch all required data from SDL before starting to alter the texture.
Uint32* pixels = nullptr;
int pitch = 0;
// Get the size of the texture.
int w, h;
SDL_QueryTexture(texture, &format, nullptr, &w, &h);
// Now let's make our "pixels" pointer point to the texture data.
if (SDL_LockTexture(texture, nullptr, (void**)&pixels, &pitch))
// If the locking fails, you might want to handle it somehow. SDL_GetError(); or something here.
pixelFormat.format = format;
// Now you want to format the color to a correct format that SDL can use.
// Basically we convert our RGB color to a hex-like BGR color.
Uint32 color = SDL_MapRGB(&pixelFormat, R, G, B);
// Before setting the color, we need to know where we have to place it.
Uint32 pixelPosition = y * (pitch / sizeof(unsigned int)) + x;
// Now we can set the pixel(s) we want.
pixels[pixelPosition] = color;
// Also don't forget to unlock your texture once you're done.
Now, you should also note that modifying textures in code is relatively expensive. Also the code is not very clean, as editing C++ int pointer arrays and translating colours into different formats can cause problems, as what goes on where might not be as clear as needed.
However doing this only when absolutely necessary shouldn't cause too much problems.
You also might want to consider using
SDL_SetRenderTarget and modifying the texture by rendering to it. However for some tasks, rendering primitives to the texture might not be an option, and that's a case when modifying the pixels like this might be come handy.