I have a Canon EOS Rebel T5. How can I achieve this using flash? Anytime I take pictures with flash, the background also gets brighter. I really want to put emphasis on the subject and have a dark/black background.
This is simple: more distance. Light falls off with the square of the distance from the flash, so it doesn't need to be a huge, but the basic idea is to get the background far enough away that the flash doesn't light it effectively.
If you are distance-constrained, you can use an external flash to the side and "flag" it — that is, block some of the light with a piece of cloth or cardboard or similar — so less is directed towards the background. That'll buy you a little more space, but since light bounces around, you still need some room.
You'll also need to make sure your flash is the primary source of light — you'll want to use the camera's flash sync speed and probably use a narrower aperture and more powerful flash, so that the room lighting is irrelevant.
Lighting for shots such as this one is not about absolute lighting levels, it is about lighting ratios. The 'dark' parts of the picture don't need to be in absolute darkness. They just need to be less bright than the bright parts of the scene by enough to make them dark by controlling exposure.
As long as the part of the scene you want illuminated is lit brightly enough compared to the part you don't want to be bright and exposure is set appropriately you'll get the effect you are looking for.
This image was taken in fairly pedestrian indoor lighting levels. There was a black curtain about 15 feet behind the subject. A fairly hot flash was illuminating the subject at about a 45° angle to lower camera left.
Here is the wider scene at the same exposure setting for a test shot before the curtain was adjusted to cover the background behind the subject. The ambient light is underexposed by about 4 stops.
Here's an uncropped version of the first image above with the exposure pushed three stops in the raw conversion. At that point the house lights had been cut, but the overhead stage lights were the same as in the test shot. You can see the flash at lower left is spilling onto the curtain a bit, but the difference between the brightness of the curtain and the face is enough to leave the curtain very dark at the selected exposure settings as seen in the crop above.
When you want the background to be dark the key is to get enough distance between your subject and the background so that light illuminating the parts of the scene you want to be bright does not spill onto the background you want to be darker. The same is true of walls off to camera left and right: they need to be far enough away and non-reflective enough that light won't bounce off of them and back into the scene.
With a dark background you can flag your off camera flash to reduce light spilling onto the background if you need to.
For how this works out with a dark background, please see: If I want to shoot darker shots, is it better to increase the lighting and then darken in post to retain clarity? Note that the dark areas in the photo can be much brighter than they look in the image, exposure just has to be set to 'kill the ambient' and the parts you want to be bright have to be lit brightly enough to still be bright at that reduced exposure value.
For another question that deals with a lighter background, please see: How to get this particular black and white look?
It's all about the ambient/flash ratio.
In order to get your background to go black, it has to be underexposed in comparison with the flash-lit portions of the scene, to the point of going to black, and is known as "killing the ambient." In other words, without the flash, you should get a black frame.
This isn't always possible. Particularly in bright daylight. And if you can't do HSS (high-speed sync).
The shot you show as an example looks like it was taken at night. At night, it's very easy to get a black frame without any flash. Then adding flash means only the subject/bits of the scene that are lit by the flash will show in the exposure.
In addition, you may also need to control the spread/spill of the light coming from the flash. If the flash also manages to illuminate your background (say, a wall three feet behind your subject), it's going to show up, too. Grids, snoots, and barn doors can help to control the spill of the light. But distance separation between your subject and background can also do this. But it may be more distance than you think.
See this youtube excerpt from David Hobby's Strobist DVDs. It may give you a sense of the geometry/distance involved in not cross-contaminating lights.