You only need to extract Z-values from your raster, and attach them to the contour lines you have just obtained.
(1) You have a raster and contour lines. (Make sure you have elevation attribute like
ELEV in your line shapefile).
(2) Next, activate GRASS v.drape which you can find in the Processing Toolbox
GRASS GIS 7 | Vector.
Input vector layer : Your contour layer.
Elevation raster... : Your raster.
WHERE conditions of SQL... : You cannot leave it blank. Hence please add any conditions you can think of. In this case I set
"ELEV" < 100 so that I can select everything.
Vector Z for unknown height: I set 1000 which was reasonably out of my value range.
(3) Running this will produce a new line layer named
3D vector. You can check it by
Identify Features tool, which gives you
Closest vertex Z information.
(4) Do not forget export the (3D vector) as a new shapefile. Default setting will automatically keep the Z-dimension, but it is still better to double check Geometry type while saving.
Just to add; if you import the 3D-contour and your raster into SAGA GIS, you can use 3D viewer to visually check your output.