Thank you for your help. I think all of the answers provided could work. However, my ByteArray contains raw bytes. That's those solutions didn't work for my code.
However, I found a solution. Maybe it will help others who have the same problem I had.
static byte[] PadLines(byte[] bytes, int rows, int columns) {
   int currentStride = columns; // 3
   int newStride = columns;  // 4
   byte[] newBytes = new byte[newStride * rows];
   for (int i = 0; i < rows; i++)
       Buffer.BlockCopy(bytes, currentStride * i, newBytes, newStride * i, currentStride);
   return newBytes;
 }
 int columns = imageWidth;
 int rows = imageHeight;
 int stride = columns;
 byte[] newbytes = PadLines(imageData, rows, columns);
 Bitmap im = new Bitmap(columns, rows, stride, 
          PixelFormat.Format8bppIndexed, 
          Marshal.UnsafeAddrOfPinnedArrayElement(newbytes, 0));
 im.Save("C:\\Users\\musa\\Documents\\Hobby\\image21.bmp");
This works for 8bit 256 bpp (Format8bppIndexed). If your image has a different format you should change PixelFormat .
I still have a problem with colors right now. As soon as I solve that I will edit my answer for other users.
*PS = I am not sure about stride value but for 8bit it should be equal to columns.
Also this function works for me... it copies 8 bit greyscale image into a 32bit layout.
public void SaveBitmap(string fileName, int width, int height, byte[] imageData)
        {
            
            byte[] data = new byte[width * height * 4];
            int o = 0;
            for (int i = 0; i < width * height; i++)
            {
                byte value = imageData[i];
                
                data[o++] = value;
                data[o++] = value;
                data[o++] = value;
                data[o++] = 0; 
            }
            unsafe
            {
                fixed (byte* ptr = data)
                {
                    
                    using (Bitmap image = new Bitmap(width, height, width * 4,
                                PixelFormat.Format32bppRgb, new IntPtr(ptr)))
                    {
                        
                        image.Save(Path.ChangeExtension(fileName, ".jpg"));
                    }
                }
            }
        }